﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotionControl;
using WHW_NetUtility;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using System.IO;
using HalconDotNet;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using XXTUserUI;

namespace MainFrame
{

    public delegate int _AxisHome(int nAxis);
    public delegate void _displayAlarmInfo(AlarmInfo alarmInfo);//切换帐户
    public partial class GlobalMotion
    {
        public static _displayAlarmInfo addAlarmInfo;
        public static event _AxisHome AxisHome;

        //全局运动变量
        public static CardMotion Card_1;
        public static CardExt CardExt_1;
        public static CardExt CardExt_2;
        //public static CardMotion Card_3;
        public static string cardName = "DMC3800";
        public static bool[] Input_Card1 = new bool[16];
        public static bool[] Input_CardEx1 = new bool[16];
        public static bool[] Input_CardEx2 = new bool[32];
        public static bool[] Output_Card1 = new bool[16];
        public static bool[] Output_CardEx1 = new bool[16];
        public static bool[] Output_CardEx2 = new bool[32];
        public static int motor_time = 15000;//电机运动到位时间

        public static xPostion VisionDown_LeftResultPlate =new xPostion();//左下相机偏值
        public static xPostion VisionDown_RightResultPlate = new xPostion();//右下相机偏值
        public static xPostion VisionUP_LeftResultPlate = new xPostion();//左上相机偏值
        public static xPostion VisionUP_RightResultPlate = new xPostion();//右上相机偏值

        public static bool cardInit()
        {
            try
            {
                if (GlobalVariable.ListCard == null || GlobalVariable.ListCard.Count < 1)
                {
                    int cardCount = GlobalVariable.ListCard == null ? 0 : GlobalVariable.ListCard.Count;
                    MessageBox.Show($"控制卡没有初始化");
                    displalyInfo.displayInfoMain($"控制卡没有全部初始化,找到控制卡数量：{cardCount}");
                    return false;
                }
                Card_1 = (CardMotion)GlobalVariable.ListCard[(int)e_Card.Card1];
                CardExt_1 = (CardExt)GlobalVariable.ListCard[(int)e_Card.CardEx1];
                CardExt_2 = (CardExt)GlobalVariable.ListCard[(int)e_Card.CardEx2];
                //Card_3 = (CardMotion)GlobalVariable.ListCard[2];
                displalyInfo.displayInfoMain($"控制卡已全部初始化");
                return true;
            }
            catch (Exception ex)
            {
                Log4Helper.WriteLog(ex);
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e_Convery"></param>
        /// <returns>-1表示异常  1表示OK</returns>
        public static int ConveryControrl(e_ConveryControl e_Convery, e_MachineStatus e_Staus = e_MachineStatus.暂停控制)
        {
            try
            {
                bool isOK = true;
                switch (e_Staus)
                {
                    case e_MachineStatus.无控制:
                        break;
                    case e_MachineStatus.暂停控制:
                        {
                            var nstop = MachineState(e_MachineStatus.暂停控制);
                            if (nstop != 1)
                                return -1;
                        }
                        break;
                }
                switch (e_Convery)
                {
                    case e_ConveryControl.上层输送启动:
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送左].ClearPos();
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送右].ClearPos();
                        if (!GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送左].m_AxisSts.Motion)
                            isOK &= GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送左].JogMove(e_moveDirection.positive);
                        if (!GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送右].m_AxisSts.Motion)
                            isOK &= GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送右].JogMove(e_moveDirection.negative);
                        break;
                    case e_ConveryControl.上层输送反转:
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送左].AxisStop();
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送右].AxisStop();
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送左].ClearPos();
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送右].ClearPos();
                        isOK &= GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送左].JogMove(e_moveDirection.negative,0.3);
                        isOK &= GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送右].JogMove(e_moveDirection.positive,0.3);
                        Thread.Sleep(200);
                        break;
                    case e_ConveryControl.NG输送启动:
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.NG输送].ClearPos();

                        isOK &= GlobalMotion.Card_1.AxisList[(int)e_card1_axis.NG输送].JogMove(e_moveDirection.positive);
                        break;
                    case e_ConveryControl.下层输送启动:
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送右].ClearPos();
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送左].ClearPos();
                        if (GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送右].m_AxisSts.Motion || GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送左].m_AxisSts.Motion)
                        {

                        }
                        else
                        {
                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送右].JogMove(e_moveDirection.positive, 1);
                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送左].JogMove(e_moveDirection.negative, 1);
                        }
                        isOK = true;

                        break;
                    case e_ConveryControl.NG输送停止:
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.NG输送].ClearPos();
                        isOK &= GlobalMotion.Card_1.AxisList[(int)e_card1_axis.NG输送].AxisStop();

                        break;
                    case e_ConveryControl.上层输送停止:
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送左].ClearPos();
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送右].ClearPos();
                        isOK &= GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送左].AxisStop();
                        isOK &= GlobalMotion.Card_1.AxisList[(int)e_card1_axis.上层输送右].AxisStop();
                        break;
                    case e_ConveryControl.下层输送停止:
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送右].ClearPos();
                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送左].ClearPos();
                        isOK &= GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送右].AxisStop();
                        isOK &= GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送左].AxisStop();
                        break;
                    case e_ConveryControl.下层治具放行:
                        isOK = SetAir(e_output_extCard2.下层阻挡气缸1, true, e_input_extCard2.下层阻挡气缸原点1, false) == 1;

                        break;
                    case e_ConveryControl.下层治具阻挡:
                        isOK = SetAir2(e_output_extCard2.下层阻挡气缸1, false, e_input_extCard1.下层阻挡气缸到位1, false) == 1;
                        break;
                }
                displalyInfo.displayInfoMain(e_Convery.ToString() + (isOK ? "成功" : "失败"));
                return isOK ? 1 : -1;
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("ConveryControrl" + ex.Message);
                return -1;
            }

        }
      

        /// <summary>
        /// 电机JOG动作
        /// </summary>
        /// <param name="axisNo">轴号</param>
        /// <param name="dir">电机运动的方向</param>
        /// <param name="in_union">电机动作停止的条件（比如电机到原点要停止，这个就指电机的原点信号）</param>
        /// <returns></returns>
        public static bool JogMove(int axisNo, e_moveDirection dir, int in_union)
        {
            try
            {
                Stopwatch sw = new Stopwatch();
                GlobalMotion.Card_1.AxisList[axisNo].JogMove(dir);
                sw.Restart();
                while (true)
                {
                    if (GlobalMotion.Card_1.GetInputIOStatus(in_union))
                    {
                        GlobalMotion.Card_1.AxisList[axisNo].AxisStop();
                        return true;
                    }
                    if (sw.ElapsedMilliseconds > motor_time)
                    {
                        GlobalMotion.Card_1.AxisList[axisNo].AxisStop();
                        displalyInfo.displayInfoMain($"电机[轴号：{axisNo}](JogMove) 到位超时");
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain($"电机[轴号：{axisNo}](JogMove) 到位出错:{ex}");
                return false;
            }
        }

        /// <summary>
        /// 电机JOG动作
        /// </summary>
        /// <param name="cardNo">卡号</param>
        /// <param name="axisNo">轴号</param>
        /// <param name="dir">电机运动的方向</param>
        /// <param name="isStop">电机是运动还是停止</param>
        /// <returns></returns>
        public static bool JogMove(int cardNo, int axisNo, e_moveDirection dir, bool isStop = false)
        {
            try
            {
                if (isStop)
                {
                    ((CardMotion)GlobalVariable.ListCard[cardNo]).AxisList[axisNo].AxisStop();
                }
                else
                {
                    ((CardMotion)GlobalVariable.ListCard[cardNo]).AxisList[axisNo].JogMove(dir);
                }

                return true;
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain($"电机[卡号：{cardNo} ,轴号：{axisNo}](JogMove) 到位出错:{ex}");
                return false;
            }
        }

        /// <summary>
        /// 电机JOG动作
        /// </summary>
        /// <param name="axisNo">轴号</param>
        /// <param name="in_union">电机动作对应的端口（通常指原点）</param>
        /// <param name="stop_port">电机停止对应的输入口（通常指正负限位）</param>
        /// <returns></returns>
        public static bool JogMove(int axisNo, e_moveDirection dir, int in_union, int stop_port)
        {
            try
            {
                Stopwatch sw = new Stopwatch();
                GlobalMotion.Card_1.AxisList[axisNo].JogMove(dir);
                sw.Restart();
                while (true)
                {
                    if (GlobalMotion.Card_1.GetInputIOStatus(in_union))
                    {
                        GlobalMotion.Card_1.AxisList[axisNo].AxisStop();
                        return true;
                    }
                    if (GlobalMotion.Card_1.GetInputIOStatus(stop_port))
                    {
                        displalyInfo.displayInfoMain($"电机[轴号：{axisNo}](JogMove) 到限位位置");
                        GlobalMotion.Card_1.AxisList[axisNo].AxisStop();
                        return false;
                    }
                    if (sw.ElapsedMilliseconds > motor_time)
                    {
                        displalyInfo.displayInfoMain($"电机[轴号：{axisNo}](JogMove) 到位超时");
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                GlobalMotion.Card_1.AxisList[axisNo].AxisStop();
                displalyInfo.displayInfoMain($"电机[轴号：{axisNo}](JogMove) 到位出错:{ex}");
                return false;
            }
        }

        /// <summary>
        /// 运动到位置 单轴
        /// </summary>
        /// <param name="position">轴距离</param>
        /// <param name="axisOne">轴号</param>
        public static bool toPosition(double position, int axisOne, double VelRate, bool isAbs, int limitPort = -1, bool isPortRev = false)
        {
            Stopwatch getPositionSW = new Stopwatch();
            try
            {
                if (b_canMove)
                {
                    GlobalMotion.Card_1.AxisList[axisOne].PointMove(position, VelRate, isAbs);
                    getPositionSW.Restart();
                    while (true)
                    {
                        Thread.Sleep(5);
                        if (limitPort != -1)
                        {
                            if (isPortRev)
                            {
                                if (!GlobalMotion.Card_1.GetInputIOStatus(limitPort))
                                {
                                    GlobalMotion.Card_1.AxisList[axisOne].AxisStop();
                                    return true;
                                }
                            }
                            else
                            {
                                if (GlobalMotion.Card_1.GetInputIOStatus(limitPort))
                                {
                                    GlobalMotion.Card_1.AxisList[axisOne].AxisStop();
                                    return true;
                                }
                            }
                        }
                        if (Card_1.AxisList[axisOne].m_AxisSts.Arrive)
                        {
                            GlobalMotion.Card_1.AxisList[axisOne].AxisStop();
                            return true;
                        }
                        if (getPositionSW.ElapsedMilliseconds > motor_time)
                        {
                            GlobalMotion.Card_1.AxisList[axisOne].AxisStop();
                            GlobalVar.errorTips[(int)e_errorType.axisError].haveInfo = true;
                            GlobalVar.errorTips[(int)e_errorType.axisError].Info = "运动超时";
                            displalyInfo.displayInfoMain?.Invoke("运行到指定位置超时，请检查");
                            return false;
                        }

                        if (GlobalVar.isEstop)
                        {
                            GlobalMotion.Card_1.AxisList[axisOne].AxisStop();
                            GlobalMotion.errorTips(e_errorType.axisError, $"急停状态");
                            return false;
                        }
                    }
                }
                else
                {

                    displalyInfo.displayInfoMain?.Invoke($"轴[轴号：{axisOne}]不满足运动条件，请检查");
                    GlobalVar.warningTips[(int)e_warningType.motor].haveInfo = true;
                    GlobalVar.warningTips[(int)e_warningType.motor].Info = "运动超时";
                    GlobalMotion.Card_1.AxisList[axisOne].AxisStop();
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                GlobalMotion.Card_1.AxisList[axisOne].AxisStop();//出错时，停止轴
                Log4Helper.WriteLog("GlobalMotion.toPosition", ex);
                displalyInfo.displayInfoMain("GlobalMotion.toPosition 出错" + Environment.NewLine + ex.Message);
                return false;
            }

        }

        public static bool toPosition(int cardNo, int axisNo, double position, double VelRate, bool isAbs, int limitPort = -1)
        {
            Stopwatch getPositionSW = new Stopwatch();
            try
            {
                //GlobalMotion.mainCard.AxisList[axisOne].AxisStop();//先停止轴
                if (b_canMove)
                {
                    ((CardMotion)GlobalVariable.ListCard[cardNo]).AxisList[axisNo].PointMove(position, VelRate, isAbs);
                    getPositionSW.Restart();
                    while (true)
                    {
                        Thread.Sleep(10);
                        if (limitPort != -1)
                        {
                            if (((CardMotion)GlobalVariable.ListCard[cardNo]).GetInputIOStatus(limitPort))
                            {
                                ((CardMotion)GlobalVariable.ListCard[cardNo]).AxisList[axisNo].AxisStop();
                                return true;
                            }
                        }
                        if (((CardMotion)GlobalVariable.ListCard[cardNo]).AxisList[axisNo].m_AxisSts.Arrive)
                        {
                            ((CardMotion)GlobalVariable.ListCard[cardNo]).AxisList[axisNo].AxisStop();
                            return true;
                        }
                        if (getPositionSW.ElapsedMilliseconds > motor_time)
                        {
                            ((CardMotion)GlobalVariable.ListCard[cardNo]).AxisList[axisNo].AxisStop();
                            GlobalMotion.errorTips(e_errorType.axisError, $"card:{cardNo} ，axis:{axisNo} 运动超时");
                            return false;
                        }

                        if (GlobalVar.isEstop)
                        {
                            ((CardMotion)GlobalVariable.ListCard[cardNo]).AxisList[axisNo].AxisStop();
                            GlobalMotion.errorTips(e_errorType.axisError, $"急停状态");
                            return false;
                        }
                    }
                }
                else
                {
                    GlobalMotion.warnningTips(e_warningType.motor, $"轴[卡号：{cardNo} , 轴号：{axisNo}]不满足运动条件，请检查");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                ((CardMotion)GlobalVariable.ListCard[cardNo]).AxisList[axisNo].AxisStop();//出错时，停止轴
                Log4Helper.WriteLog("GlobalMotion.toPosition", ex);
                GlobalMotion.errorTips(e_errorType.axisError, $"card:{cardNo} ，axis:{axisNo} 运动出错");
                displalyInfo.displayInfoMain("GlobalMotion.toPosition 出错" + Environment.NewLine + ex.Message);
                return false;
            }

        }

        public static bool waitMutil(List<SigleAxis> posList)
        {
            Stopwatch getPositionSW = new Stopwatch();
            getPositionSW.Reset();
            while (true)
            {
                Thread.Sleep(20);
                bool isArrive = true;
                posList.ForEach(a => { isArrive = Card_1.AxisList[a.nAxis].m_AxisSts.Arrive && isArrive; });
                if (isArrive)
                {
                    posList.ForEach(a => Card_1.AxisList[a.nAxis].AxisStop());
                    return true;
                }
                if (getPositionSW.ElapsedMilliseconds > motor_time)
                {
                    posList.ForEach(a => Card_1.AxisList[a.nAxis].AxisStop());
                    GlobalMotion.errorTips(e_errorType.axisError, $"axis:{string.Join(",", posList.Select(a => a.nAxis).ToArray())} 运动超时");
                    return false;
                }
                while (GlobalVar.isPause)
                {
                    Thread.Sleep(10);

                    if (GlobalVar.isExit || GlobalVar.isEstop || GlobalVar.isReseting)
                    {
                        posList.ForEach(a => Card_1.AxisList[a.nAxis].AxisStop());
                        // GlobalMotion.errorTips(e_errorType.axisError, $"急停状态");
                        return false;
                    }
                }

            }
        }
        public static bool toPostionMutil(List<SigleAxis> posList)
        {
            Stopwatch getPositionSW = new Stopwatch();
            try
            {
                if (b_canMove)
                {
                    posList.ForEach(item =>
                    {
                        Card_1.AxisList[item.nAxis].PointMove(item.pos, item.velrate, item.IsAbs);
                    });
                    getPositionSW.Restart();
                    Thread.Sleep(20);
                    while (true)
                    {
                        Thread.Sleep(5);
                        bool isArrive = true;
                        posList.ForEach(a =>
                        {
                            {
                                var state = Card_1.AxisList[a.nAxis].m_AxisSts;
                                isArrive = state.Arrive && isArrive;
                                if (state.Alarm)
                                    isArrive = false;
                            }
                        });
                        if (isArrive)
                        {
                            posList.ForEach(a => Card_1.AxisList[a.nAxis].AxisStop());
                            return true;
                        }
                        if (getPositionSW.ElapsedMilliseconds > motor_time)
                        {
                            posList.ForEach(a => Card_1.AxisList[a.nAxis].AxisStop());
                            GlobalMotion.errorTips(e_errorType.axisError, $"axis:{string.Join(",", posList.Select(a => a.nAxis).ToArray())} 运动超时");
                            return false;
                        }
                        if (GlobalVar.isExit || GlobalVar.isEstop)
                        {
                            posList.ForEach(a => Card_1.AxisList[a.nAxis].AxisStop());
                            // GlobalMotion.errorTips(e_errorType.axisError, $"急停状态");
                            return false;
                        }
                    }
                }
                else
                {
                    GlobalMotion.warnningTips(e_warningType.motor, $"轴[轴号{string.Join(",", posList.Select(a => a.nAxis).ToArray())}不满足运动条件，请检查");
                    return false;
                }
            }
            catch (Exception ex)
            {
                posList.ForEach(a => Card_1.AxisList[a.nAxis].AxisStop());
                Log4Helper.WriteLog("toPostionMutil", ex);
                GlobalMotion.errorTips(e_errorType.axisError, $"axis{string.Join(",", posList.Select(a => a.nAxis).ToArray())}运动出错");
                displalyInfo.displayInfoMain("toPostionMutil 出错" + Environment.NewLine + ex.Message);
                return false;
            }
        }

        public static void ButtonControl()
        {

            bool isStart = true;
            bool isAirAll = true;
            Thread.Sleep(1000);
            Stopwatch sw_Stop = new Stopwatch();
            sw_Stop.Restart();
            bool IsEstoping = false;
            while (true)
            {
                try
                {
                    Thread.Sleep(50);
                    if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.总气源压力报警])
                    {
                        if (isAirAll || !GlobalVar.isEstop)
                        {
                            isAirAll = false;
                            GlobalMotion.MachineState(e_MachineStatus.异常急停, "总气源压力报警");
                        }
                    }
                    else
                        isAirAll = true;
                    if (!GlobalMotion.CardExt_2.GetInputIOStatus((int)e_input_extCard2.复位按钮))
                    {
                        GlobalVar.btn_Home?.Invoke("复位按钮");
                    }
                    if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.急停按钮])
                    {
                        IsEstoping = true;
                        if (!GlobalVar.isEstop)
                        {
                            GlobalVar.btn_Estop?.Invoke("急停按钮");
                            GlobalMotion.MachineState(e_MachineStatus.异常急停, "硬件急停按钮按下");
                        }
                    }
                    else
                    {
                        if (IsEstoping)
                        {
                            IsEstoping = false;
                            if (GlobalVar.isEstop)
                                GlobalVar.btn_Estop?.Invoke("急停取消");
                        }
                    }
                    if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.门禁开关] && !GlobalVar.closeSave.IsSaftGate && !GlobalVar.IsManThrought)
                    {
                        if (!GlobalVar.isPause)
                        {
                            sw_Stop.Restart();
                            GlobalVar.isPause = true;
                            displalyInfo.displayErrorMain("安全门已打开  触发暂停");
                        }
                        else
                        {
                            if (sw_Stop.ElapsedMilliseconds > 10000)
                            {
                                displalyInfo.displayErrorMain("安全门已打开  暂停中");
                                sw_Stop.Restart();
                            }
                        }
                    }
                    if (GlobalVar.isExit)
                    {
                        LightState(e_LightState.全灭);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    displalyInfo.displayInfoMain("ButtonControl" + ex.Message);
                }
            }
        }

        /// <summary>
        /// 灯显示
        /// </summary>
        public static void Task_LightDisplay()
        {
            try
            {
                Stopwatch tempSw = new Stopwatch();
                while (!GlobalVar.isExit)
                {
                    tempSw.Restart();
                    Thread.Sleep(500);//0.5秒刷新一下界面
                    #region 状态灯显示
                    if (GlobalVar.isAutoRun && !GlobalVar.isEstop)
                    {
                        CardExt_2.setOut((ushort)e_output_extCard2.废料离子风, e_out_OnOff.off);
                        if (GlobalVar.IsTip || GlobalVar.IsTip_fly || GlobalVar.IsTip_Start || GlobalVar.IsTip_down)
                        {
                            GlobalMotion.LightState(e_LightState.提示);
                            Thread.Sleep(1000);
                            GlobalMotion.LightState(e_LightState.全灭);
                        }
                        else
                        {
                            if (GlobalVar.isPause)
                            {
                                GlobalMotion.LightState(e_LightState.暂停);
                            }
                            else
                            {
                                GlobalMotion.LightState(e_LightState.运行中);
                            }
                        }
                    }
                    else if (GlobalVar.isEstop)
                    {
                        GlobalMotion.LightState(e_LightState.报警);
                        Thread.Sleep(1000);
                        GlobalMotion.LightState(e_LightState.全灭);
                    }
                    else
                    {
                        CardExt_2.setOut((ushort)e_output_extCard2.废料离子风, e_out_OnOff.on);
                        GlobalMotion.LightState(e_LightState.暂停);
                    }
                    #endregion
                    if (GlobalVar.isExit)
                    {
                        CardExt_2.setOut((ushort)e_output_extCard2.废料离子风, e_out_OnOff.on);
                        GlobalMotion.LightState(e_LightState.全灭);
                        return;
                    }

                }
            }
            catch (System.Exception ex)
            {
                Log4Helper.WriteLog("LightDisplay", ex);
            }
        }
        public static void LightState(e_LightState state)
        {
            switch (state)
            {
                case e_LightState.报警:
                    {
                        CardExt_2.setOut((int)e_output_extCard2.绿灯, e_out_OnOff.on);
                        CardExt_2.setOut((int)e_output_extCard2.黄灯, e_out_OnOff.on);

                        CardExt_2.setOut((int)e_output_extCard2.红灯, e_out_OnOff.off);
                        CardExt_2.setOut((int)e_output_extCard2.蜂鸣器, e_out_OnOff.off);
                    }
                    break;
                case e_LightState.暂停:
                    {
                        CardExt_2.setOut((int)e_output_extCard2.绿灯, e_out_OnOff.on);
                        CardExt_2.setOut((int)e_output_extCard2.红灯, e_out_OnOff.on);
                        CardExt_2.setOut((int)e_output_extCard2.蜂鸣器, e_out_OnOff.on);
                        CardExt_2.setOut((int)e_output_extCard2.黄灯, e_out_OnOff.off);
                    }
                    break;
                case e_LightState.运行中:
                    {
                        CardExt_2.setOut((int)e_output_extCard2.黄灯, e_out_OnOff.on);
                        CardExt_2.setOut((int)e_output_extCard2.红灯, e_out_OnOff.on);
                        CardExt_2.setOut((int)e_output_extCard2.蜂鸣器, e_out_OnOff.on);
                        CardExt_2.setOut((int)e_output_extCard2.绿灯, e_out_OnOff.off);
                    }
                    break;
                case e_LightState.提示:
                    {
                        CardExt_2.setOut((int)e_output_extCard2.黄灯, e_out_OnOff.on);
                        CardExt_2.setOut((int)e_output_extCard2.红灯, e_out_OnOff.on);


                        CardExt_2.setOut((int)e_output_extCard2.蜂鸣器, e_out_OnOff.off);
                        CardExt_2.setOut((int)e_output_extCard2.绿灯, e_out_OnOff.off);
                    }
                    break;
                default:
                    {
                        CardExt_2.setOut((int)e_output_extCard2.蜂鸣器, e_out_OnOff.on);
                        break;
                    }
            }

        }
        public static void Task_ReadInput()
        {
            try
            {
                while (!GlobalVar.isExit)
                {
                    Application.DoEvents();
                    Thread.Sleep(3);
                    var inputs1 = GlobalMotion.Card_1.m_BlnInputSts;
                    var inputsExt1 = GlobalMotion.CardExt_1.GetAllInputIO();
                    var inputsExt2 = GlobalMotion.CardExt_2.GetAllInputIO();
                  
                    if (inputs1 != null && inputs1.Length == 16)
                        Input_Card1 = inputs1.Take(8).ToArray();
                    if (inputsExt1 != null && inputsExt1.Length == 32)
                        Input_CardEx1 = inputsExt1.Take(16).ToArray();
                    if (inputsExt2 != null && inputsExt2.Length == 32)
                        Input_CardEx2 = inputsExt2;
                    
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_ReadInput" + ex.Message);

            }
        }
        public static void Task_ReadOutput()
        {
            try
            {
                while (!GlobalVar.isExit)
                {
                    Application.DoEvents();
                    Thread.Sleep(3);
                   
                    var outputs1 = GlobalMotion.Card_1.m_BlnOutputSts;
                    var outputsExt1 = GlobalMotion.CardExt_1.GetAllOutputIO();
                    var outputsExt2 = GlobalMotion.CardExt_2.GetAllOutputIO();
                   
                    if (outputs1 != null && outputs1.Length == 16)
                        Output_Card1 = outputs1.Take(8).ToArray();
                    if (outputsExt1 != null && outputsExt1.Length == 32)
                        Output_CardEx1 = outputsExt1.Take(16).ToArray();
                    if (outputsExt2 != null && outputsExt2.Length == 32)
                        Output_CardEx2 = outputsExt2;
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_ReadInput" + ex.Message);

            }
        }
        public static int nhave = 20;
        /// <summary>
        /// 是否离开（放标位）
        /// </summary>
        /// <returns></returns>
        public static int IsNGlabelOk()
        {
            var nOK1 = Input_CardEx1[(int)e_input_extCard1.平台1吸标NG取料位] && !Input_CardEx1[(int)e_input_extCard1.平台1吸标NG放料位];
            var nOK2 = Input_CardEx1[(int)e_input_extCard1.平台2吸标NG取料位] && !Input_CardEx1[(int)e_input_extCard1.平台2吸标NG放料位];
            var res = (nOK1 && nOK2) ? 1 : -1;
            displalyInfo.displayInfoMain(res == 1 ? "已离开放标位" : "未离开放标位");
            return res;
        }

        /// <summary>
        ///  是否离开（取标位）
        /// </summary>
        /// <returns></returns>
        public static int IsNGlabelPos()
        {
            var nOK1 = Input_CardEx1[(int)e_input_extCard1.平台1吸标NG放料位] && !Input_CardEx1[(int)e_input_extCard1.平台1吸标NG取料位];
            var nOK2 = Input_CardEx1[(int)e_input_extCard1.平台2吸标NG放料位] && !Input_CardEx1[(int)e_input_extCard1.平台2吸标NG取料位];
            var res = (nOK1 && nOK2) ? 1 : -1;
            displalyInfo.displayInfoMain(res == 1 ? "已离开取标位" : "未离开取标位");
            return res;
        }
        /// <summary>
        /// 是否在（放标位）
        /// </summary>
        /// <returns></returns>
        public static int IsNGlabelOkExist()
        {
            var nOK1 = !Input_CardEx1[(int)e_input_extCard1.平台1吸标NG取料位] && Input_CardEx1[(int)e_input_extCard1.平台1吸标NG放料位];
            var nOK2 = !Input_CardEx1[(int)e_input_extCard1.平台2吸标NG取料位] && Input_CardEx1[(int)e_input_extCard1.平台2吸标NG放料位];
            var res = (nOK1 && nOK2) ? 1 : -1;
            displalyInfo.displayInfoMain(res == 1 ? "在放标位" : "不在放标位");
            return res;
        }

        /// <summary>
        ///  是否在（取标位）
        /// </summary>
        /// <returns></returns>
        public static int IsNGlabelPosExist()
        {
            var nOK1 = !Input_CardEx1[(int)e_input_extCard1.平台1吸标NG放料位] && Input_CardEx1[(int)e_input_extCard1.平台1吸标NG取料位];
            var nOK2 = !Input_CardEx1[(int)e_input_extCard1.平台2吸标NG放料位] && Input_CardEx1[(int)e_input_extCard1.平台2吸标NG取料位];
            var res = (nOK1 && nOK2) ? 1 : -1;
            displalyInfo.displayInfoMain(res == 1 ? "在取标位" : "不在取标位");
            return res;
        }
        public static int MutilStep(e_Mutil_step e_Mutil, e_platePro e_Plate)
        {
            if (GlobalVar.isExit || GlobalVar.isEstop)
                return -1;
            switch (e_Mutil)
            {
                case e_Mutil_step.移至取标位取标:
                    {
                        #region NG取标状态
                        for (int m = 0; m < GlobalVar.userConfig.getLabelNGTimes; m++)
                        {
                            //if (IsNGlabelOk() != 1 || IsNGlabelPosExist() != 1)
                            var isok1 = IsNGlabelPos() != 1;
                            var isok2 = IsNGlabelOkExist() != 1;
                            if (isok1 || isok2)
                            {
                                var res1 = Step_Labeling(e_Step_Label.吸标NG旋转到放标位, e_platePro.双平台有);
                                res1 = Step_Labeling(e_Step_Label.吸标NG下压, e_platePro.双平台有);
                                if (res1 != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:吸标NG放标处理");
                                    return res1;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        #endregion
                        var nres = Step_Labeling(e_Step_Label.移至取标位上方, e_Plate);
                        if (nres != 1)
                        {
                            MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:移至取标位上方");
                            return nres;
                        }
                        //靶面取料
                        var nair = Step_Labeling(e_Step_Label.检测吸标靶面真空, e_Plate);
                        if (nair == -1)
                        {
                            nair = Step_Labeling(e_Step_Label.吸标NG下压, e_platePro.双平台有);

                            if (nair != 1)
                            {
                                MachineState(e_MachineStatus.异常急停, $"双平台有{e_LabelingFlow.ToString()}:吸标NG下压");
                                return nair;
                            }

                            nres = Step_Labeling(e_Step_Label.取标气缸下压, e_Plate);
                            if (nres != 1)
                            {
                                MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:取标气缸下压");
                                return nres;
                            }  
                            Step_Labeling(e_Step_Label.飞达吹气, e_Plate);
                            nres = Step_Labeling(e_Step_Label.取标位向下移动, e_Plate);
                            if (nres != 1)
                            {
                                MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:取标位向下移动");
                                return nres;
                            }

                            nres = Step_Labeling(e_Step_Label.取标签吸真空, e_Plate);
                            int nres1 = Step_Labeling(e_Step_Label.移至取标位上方, e_Plate);
                            if (nres1 != 1)
                            {
                                MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:移至取标位上方");
                                return nres1;
                            }
                            Step_Labeling(e_Step_Label.飞达关气, e_Plate);
                        }
                        else
                        {

                            if (nair == (int)e_airResult.平台2已吸有料 && e_Plate == e_platePro.双平台有)
                            {
                                var tempPlate = e_platePro.平台1;
                                nres = Step_Labeling(e_Step_Label.取标气缸下压, tempPlate);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:取标气缸下压");
                                    return nres;
                                }
                                Step_Labeling(e_Step_Label.飞达吹气, tempPlate);
                                nres = Step_Labeling(e_Step_Label.取标位向下移动, tempPlate);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:取标位向下移动");
                                    return nres;
                                }
                                nres = Step_Labeling(e_Step_Label.取标签吸真空, tempPlate);
                                nres = Step_Labeling(e_Step_Label.移至取标位上方, tempPlate);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至取标位上方");
                                    return nres;
                                }
                                Step_Labeling(e_Step_Label.飞达关气, tempPlate);

                            }//2号已有  1号没有
                            else if (nair == (int)e_airResult.平台1已吸有料 && e_Plate == e_platePro.双平台有) //1号已有  2号没有
                            {
                                var tempPlate = e_platePro.平台2;
                                nres = Step_Labeling(e_Step_Label.取标气缸下压, tempPlate);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:取标气缸下压");
                                    return nres;
                                }
                                Step_Labeling(e_Step_Label.飞达吹气, tempPlate);
                                nres = Step_Labeling(e_Step_Label.取标位向下移动, tempPlate);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:取标位向下移动");
                                    return nres;
                                }
                                nres = Step_Labeling(e_Step_Label.取标签吸真空, tempPlate);
                                nres = Step_Labeling(e_Step_Label.移至取标位上方, tempPlate);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至取标位上方");
                                    return nres;
                                }
                                Step_Labeling(e_Step_Label.飞达关气, tempPlate);

                            }
                        }
                        nres = Step_Labeling(e_Step_Label.检测吸标靶面真空, e_platePro.双平台有);//这里复检两个一定是吸好膜
                        //if (nres != -1)
                        //{
                        //    if (e_Plate == e_platePro.双平台有)
                        //    {
                        //        if (nres != -1)
                        //            return nres;
                        //    }
                        //    return -2;//单平台吸标失败
                        //}
                        return nres; //-1表示异常
                    }
                    break;
                case e_Mutil_step.等待飞达出标完成:
                    {

                        var sw_fly = new Stopwatch();
                        sw_fly.Restart();
                        while (!GlobalVar.isEstop)
                        {
                            var IsFly = false;
                            switch (e_Plate)
                            {
                                case e_platePro.双平台有:
                                    IsFly = GlobalVar.isFlying1OK && GlobalVar.isFlying2OK;
                                    break;
                                case e_platePro.平台1:
                                    IsFly = GlobalVar.isFlying1OK;
                                    break;
                                case e_platePro.平台2:
                                    IsFly = GlobalVar.isFlying2OK;
                                    break;
                            }
                            if (sw_fly.ElapsedMilliseconds > 5000)
                            {
                                displalyInfo.displayInfoMain($"等待{e_Plate.ToString()}飞达出标完成");
                                sw_fly.Restart();
                            }
                            if (IsFly && GlobalVar.userConfig.IsAutoFly)
                                break;
                            if (!GlobalVar.userConfig.IsAutoFly)
                                break;
                        }

                    }
                    break;
                case e_Mutil_step.吸标NG取标流程:
                    {
                        
                        bool isMove1 = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Z轴].PointMove(0, true);
                        bool isMove2 = true;
                        if (GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].m_AxisSts.CurrPosi>1)
                        {
                            isMove2 = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].PointMove(-5, true);
                        }
                        
                        var resOK1 = Step_Labeling(e_Step_Label.取标气缸抬起, e_platePro.双平台有);
                        //if (!isMove1)
                        //{
                        //    MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:吸标NG旋转到取标位");
                        //    return -1;
                        //}
                        //if (!isMove2)
                        //{
                        //    MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:吸标NG旋转到取标位 贴标Y轴NG");
                        //    return -1;
                        //}
                        resOK1 = Step_Labeling(e_Step_Label.吸标NG旋转到取标位,e_Plate);
                        if (resOK1 != 1)
                        {
                            MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:吸标NG旋转到取标位");
                            return resOK1;
                        }

                        //isMove2 = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].PointMove(-5, true);
                        //if (!isMove2)
                        //{
                        //    MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:吸标NG旋转到取标位 贴标Y轴NG");
                        //    return -1;
                        //}
                        resOK1 = Step_Labeling(e_Step_Label.吸标NG下压, e_Plate);
                        if (resOK1 != 1)
                        {
                            MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:吸标NG下压");
                            return resOK1;
                        }
                        resOK1 = Step_Labeling(e_Step_Label.吸标NG吸气, e_Plate);
                        resOK1 = Step_Labeling(e_Step_Label.吸标NG旋转到放标位, e_Plate);
                        if (resOK1 != 1)
                        {
                            MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:吸标NG旋转到放标位");
                            return resOK1;
                        }
                        resOK1 = Step_Labeling(e_Step_Label.吸标NG下压, e_platePro.双平台有);

                        if (resOK1 != 1)
                        {
                            MachineState(e_MachineStatus.异常急停, $"双平台有{e_LabelingFlow.ToString()}:吸标NG下压");
                            return resOK1;
                        }
                        resOK1 = Step_Labeling(e_Step_Label.吸标NG破气, e_Plate);
                        return resOK1;
                    }
                    break;
           
            }
            return 1;
        }
     
        public static TipForm tipForm;
        public static FlyTipForm tipFlyForm;
        public static object tip_object = new object();
        public static object tipfly_object = new object();
        public static int TipInfo(string msg)
        {
            ///触发蜂鸣器
            ///触发弹窗
            lock (tip_object)
            {
                GlobalVar.IsTip = true;
                GlobalVar.IsTipNG = false;
                GlobalVar.IsTipOK = false;
                displalyInfo.displayErrorMain(msg);
                if (GlobalVar.userConfig.UploadInfo.IsUploadUrl)
                {
                    if (!string.IsNullOrEmpty(GlobalVar.userConfig.UploadInfo.url_AlarmUpload))
                    {
                        UploadInterface.upload_AlarmUpload(msg);
                    }
                }
                tipForm = new TipForm(msg);
                tipForm.ShowDialog();
                GlobalVar.IsTip = false;
            }
            return GlobalVar.IsTipOK ? 1 : -1;
        }
        public static int TipInfo_fly(string msg)
        {
            ///触发蜂鸣器
            ///触发弹窗
            lock (tipfly_object)
            {
                GlobalVar.IsTip_fly = true;
                GlobalVar.IsTipNG_fly = false;
                GlobalVar.IsTipOK_fly = false;
                displalyInfo.displayErrorMain(msg);
                if (GlobalVar.userConfig.UploadInfo.IsUploadUrl)
                {
                    if (!string.IsNullOrEmpty(GlobalVar.userConfig.UploadInfo.url_AlarmUpload))
                    {
                        UploadInterface.upload_AlarmUpload(msg);
                    }
                }
                tipFlyForm = new FlyTipForm(msg);
                tipFlyForm.ShowDialog();
                GlobalVar.IsTip_fly = false;
            }
            return GlobalVar.IsTipOK_fly ? 1 : -1;
        }
        public static void Task_air()
        {
            try
            {
                var deleyms = 100;
                var sw_air = new Stopwatch();

                while (!GlobalVar.isExit)
                {

                    Thread.Sleep(5);
                    if (!GlobalVar.isEstop)
                    {
                        if (GlobalVar.isAutoRun && !GlobalVar.IsManThrought)
                        {
                            if (GlobalVar.air1up_start)///延时起来
                            {
                                GlobalVar.air1up_start = false;
                                GlobalVar.air1up_end = false;
                                Thread.Sleep(deleyms);
                                var nres = Step_Labeling(e_Step_Label.取标气缸抬起, e_platePro.平台1);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:平台1取标气缸抬起");
                                    continue;
                                }
                                GlobalVar.air1up_end = true;
                            }
                            if (GlobalVar.air2up_start)///延时起来
                            {
                                GlobalVar.air2up_start = false;
                                GlobalVar.air2up_end = false;
                                Thread.Sleep(deleyms);
                                var nres = Step_Labeling(e_Step_Label.取标气缸抬起, e_platePro.平台2);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:平台2取标气缸抬起");
                                    continue;
                                }
                                GlobalVar.air2up_end = true;
                            }
                            if (GlobalVar.air12up_start)///延时起来
                            {
                                GlobalVar.air12up_start = false;
                                GlobalVar.air12up_end = false;
                                Thread.Sleep(deleyms);
                                var nres = Step_Labeling(e_Step_Label.取标气缸抬起, e_platePro.双平台有);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:双平台取标气缸抬起");
                                    continue;
                                }
                                GlobalVar.air12up_end = true;
                            }
                            if (GlobalVar.air1down_start)///马上下压
                            {
                                GlobalVar.air1down_start = false;
                                GlobalVar.air1down_end = false;

                                var nres = Step_Labeling(e_Step_Label.取标气缸下压, e_platePro.平台1);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:平台1取标气缸抬起");
                                    continue;
                                }
                                GlobalVar.air1down_end = true;
                            }
                            if (GlobalVar.air2down_start)///马上下压
                            {
                                GlobalVar.air2down_start = false;
                                GlobalVar.air2down_end = false;

                                var nres = Step_Labeling(e_Step_Label.取标气缸下压, e_platePro.平台2);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:平台2取标气缸抬起");
                                    continue;
                                }
                                GlobalVar.air2down_end = true;
                            }
                            if (GlobalVar.air12down_start)///马上下压
                            {
                                GlobalVar.air12down_start = false;
                                GlobalVar.air12down_end = false;

                                var nres = Step_Labeling(e_Step_Label.取标气缸下压, e_platePro.双平台有);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:双平台取标气缸抬起");
                                    continue;
                                }
                                GlobalVar.air12down_end = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_Laser" + ex.Message);
            }
        }
        /// <summary>
        /// 吹气除尘
        /// </summary>
        public static void Task_air_cut()
        {
            try
            {
                var deleyms = 100;
                var sw_air = new Stopwatch();

                while (!GlobalVar.isExit)
                {

                    Thread.Sleep(5);
                    if (!GlobalVar.isEstop)
                    {
                        if (GlobalVar.isAutoRun && !GlobalVar.IsManThrought)
                        {
                            if (GlobalVar.IsAirCut)
                            {
                                GlobalVar.IsAirCut = false;
                                GlobalMotion.Step_Cut(e_Step_Cut.吹气除尘, e_platePro.双平台有, e_MachineStatus.无控制);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_Laser" + ex.Message);
            }
        }
        private static int waitforAir(bool up, e_platePro e_Plate)
        {
            //Stopwatch sw = new Stopwatch();
            //sw.Restart();
            switch (e_Plate)
            {
                case e_platePro.平台1:
                    if (up)
                    {
                        if (GlobalVar.air1up_start)
                        {
                            Thread.Sleep(20);
                            if (GlobalVar.air1up_start)
                                return -1;
                        }
                        while (!GlobalVar.air1up_end)
                        {
                            Thread.Sleep(2);
                            if (GlobalVar.isEstop || GlobalVar.isExit || GlobalVar.isReseting || GlobalVar.isPause)
                                break;
                        }
                        GlobalMotion.MachineState(e_MachineStatus.暂停控制);
                        return GlobalVar.air1up_end ? 1 : -1;
                    }
                    else
                    {
                        if (GlobalVar.air1down_start)
                        {
                            Thread.Sleep(20);
                            if (GlobalVar.air1down_start)
                                return -1;
                        }
                        while (!GlobalVar.air1down_end)
                        {
                            Thread.Sleep(2);
                            if (GlobalVar.isEstop || GlobalVar.isExit || GlobalVar.isReseting || GlobalVar.isPause)
                                break;
                        }
                        GlobalMotion.MachineState(e_MachineStatus.暂停控制);
                        return GlobalVar.air1down_end ? 1 : -1;
                    }
                    break;
                case e_platePro.平台2:
                    if (up)
                    {
                        if (GlobalVar.air2up_start)
                        {
                            Thread.Sleep(20);
                            if (GlobalVar.air1up_start)
                                return -1;
                        }
                        while (!GlobalVar.air2up_end)
                        {
                            Thread.Sleep(2);
                            if (GlobalVar.isEstop || GlobalVar.isExit || GlobalVar.isReseting || GlobalVar.isPause)
                                break;
                        }
                        GlobalMotion.MachineState(e_MachineStatus.暂停控制);
                        return GlobalVar.air2up_end ? 1 : -1;
                    }
                    else
                    {
                        if (GlobalVar.air2down_start)
                        {
                            Thread.Sleep(20);
                            if (GlobalVar.air2down_start)
                                return -1;
                        }
                        while (!GlobalVar.air2down_end)
                        {
                            Thread.Sleep(2);
                            if (GlobalVar.isEstop || GlobalVar.isExit || GlobalVar.isReseting || GlobalVar.isPause)
                                break;
                        }
                        GlobalMotion.MachineState(e_MachineStatus.暂停控制);
                        return GlobalVar.air2down_end ? 1 : -1;
                    }
                    break;
                case e_platePro.双平台有:
                    if (up)
                    {
                        if (GlobalVar.air12up_start)
                        {
                            Thread.Sleep(20);
                            if (GlobalVar.air12up_start)
                                return -1;
                        }
                        while (!GlobalVar.air12up_end)
                        {
                            Thread.Sleep(2);
                            if (GlobalVar.isEstop || GlobalVar.isExit || GlobalVar.isReseting || GlobalVar.isPause)
                                break;
                        }
                        GlobalMotion.MachineState(e_MachineStatus.暂停控制);
                        return GlobalVar.air12up_end ? 1 : -1;
                    }
                    else
                    {
                        if (GlobalVar.air12down_start)
                        {
                            Thread.Sleep(20);
                            if (GlobalVar.air12down_start)
                                return -1;
                        }
                        while (!GlobalVar.air12down_end)
                        {
                            Thread.Sleep(2);
                            if (GlobalVar.isEstop || GlobalVar.isExit || GlobalVar.isReseting || GlobalVar.isPause)
                                break;
                        }
                        GlobalMotion.MachineState(e_MachineStatus.暂停控制);
                        return GlobalVar.air12down_end ? 1 : -1;
                    }
                    break;
            }
            return -1;
        }
        /// <summary>
        /// 实时检测膜掉落位置
        /// </summary>
        public static void Task_CheckPCS()
        {
            try
            {
                while (!GlobalVar.isExit)
                {
                    Thread.Sleep(300);
                    if (!GlobalVar.isEstop)
                    {
                        if (GlobalVar.isAutoRun && !GlobalVar.userConfig.IsGetLabelOK && !GlobalVar.IsManThrought)
                        {
                            if (GlobalVar.IsEndWork || GlobalVar.IsStart_EndWork)
                            {
                                if (e_ConveryLaser == e_Flow_ConveryUp.等待一段治具到位 && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测2])
                                {
                                    continue;
                                }
                            }
                            var YPos = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标Y轴].m_AxisSts.CurrPosi;
                            var YPos1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].Y;
                            var YPos2 = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.NG放标位].Y;
                            if (YPos > (YPos1 + 10) && YPos > (YPos2 + 10))
                            {
                                var haveAir1 = !CardExt_2.GetOutputIOStatus((ushort)e_output_extCard2.吸标靶面吸气1) && !CMachine.Instance.IsTestModel;
                                var haveAir2 = !CardExt_2.GetOutputIOStatus((ushort)e_output_extCard2.吸标靶面吸气2) && !CMachine.Instance.IsTestModel;
                                if (haveAir1 && haveAir2 && Input_CardEx2[(int)e_input_extCard2.贴标升降气缸原点1] && 
                                    Input_CardEx2[(int)e_input_extCard2.贴标升降气缸原点2] && e_LabelingFlow == e_Flow_Labeling.取标签)
                                {
                                    if (Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1] && Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2])
                                    {
                                        var sw = new Stopwatch();
                                        sw.Restart();
                                        var IsLabelOk = true;
                                        while (!GlobalVar.isExit)
                                        {
                                            Thread.Sleep(3);
                                            IsLabelOk = IsLabelOk && Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1] && Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2];
                                            if (sw.ElapsedMilliseconds > GlobalVar.userConfig.LabelKeepAirTime)
                                            {
                                                break;
                                            }
                                        }
                                        if (!IsLabelOk)
                                            continue;
                                        if (GlobalVar.IsEndWork || GlobalVar.IsStart_EndWork)
                                        {
                                            if (e_ConveryLaser == e_Flow_ConveryUp.等待一段治具到位 && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测2])
                                            {
                                                continue;
                                            }
                                        }
                                        //GlobalVar.isPause = true;
                                        if (-1 == GlobalMotion.TipInfo("检测到双平台吸标板面上文字版有脱落,是否继续？是:继续   否:急停"))
                                        {
                                            GlobalMotion.MachineState(e_MachineStatus.异常急停, "检测到双平台吸标板面上文字版有脱落");
                                        }else
                                            GlobalVar.isPause = false;
                                    }
                                }
                                if (haveAir1 && Input_CardEx2[(int)e_input_extCard2.贴标升降气缸原点1] && e_LabelingFlow == e_Flow_Labeling.取标签)
                                {
                                    if (Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1])
                                    {
                                        var sw = new Stopwatch();
                                        sw.Restart();
                                        var IsLabelOk = true;
                                        while (!GlobalVar.isExit)
                                        {
                                            Thread.Sleep(3);
                                            IsLabelOk = IsLabelOk && Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1];
                                            if (sw.ElapsedMilliseconds > GlobalVar.userConfig.LabelKeepAirTime)
                                            {
                                                break;
                                            }
                                        }
                                        if (!IsLabelOk)
                                            continue;
                                        if (GlobalVar.IsEndWork || GlobalVar.IsStart_EndWork)
                                        {
                                            if (e_ConveryLaser == e_Flow_ConveryUp.等待一段治具到位 && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测2])
                                            {
                                                continue;
                                            }
                                        }
                                        //GlobalVar.isPause = true;
                                        if (-1 == GlobalMotion.TipInfo("检测到平台1吸标板面上膜有脱落,是否继续？是:继续   否:急停"))
                                        {
                                            GlobalMotion.MachineState(e_MachineStatus.异常急停, "检测到平台1吸标板面上膜有脱落");
                                        }else
                                        {
                                            GlobalVar.isPause = false;
                                        }
                                    }
                                }
                                if (haveAir2 && Input_CardEx2[(int)e_input_extCard2.贴标升降气缸原点2])
                                {
                                    if (Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2] && e_LabelingFlow == e_Flow_Labeling.取标签)
                                    {
                                        var sw = new Stopwatch();
                                        sw.Restart();
                                        var IsLabelOk = true;
                                        while (!GlobalVar.isExit)
                                        {
                                            Thread.Sleep(3);
                                            IsLabelOk = IsLabelOk && Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2];
                                            if (sw.ElapsedMilliseconds > GlobalVar.userConfig.LabelKeepAirTime)
                                            {
                                                break;
                                            }
                                        }
                                        if (!IsLabelOk)
                                            continue;
                                        if (GlobalVar.IsEndWork || GlobalVar.IsStart_EndWork)
                                        {
                                            if (e_ConveryLaser == e_Flow_ConveryUp.等待一段治具到位 && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测2])
                                            {
                                                continue;
                                            }
                                        }
                                        //GlobalVar.isPause = true;
                                        if (-1 == GlobalMotion.TipInfo("检测到平台2吸标板面上有脱落,是否继续？是:继续   否:急停"))
                                        {
                                            GlobalMotion.MachineState(e_MachineStatus.异常急停, "检测到平台2吸标板面上有脱落");
                                        }
                                        else
                                        {
                                            GlobalVar.isPause = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_CheckPCS" + ex.Message);
            }
        }
        public static e_Flow_ConveryUp e_ConveryFront = e_Flow_ConveryUp.等待入料治具到位;
        public static e_Flow_ConveryUp e_ConveryMan = e_Flow_ConveryUp.二段治具到位;
        public static e_Flow_ConveryUp e_ConveryLaser = e_Flow_ConveryUp.等待一段治具到位;
        public static e_Flow_ConveryUp e_ConveryOver = e_Flow_ConveryUp.等待一段治具到位;
        public static e_Flow_ConveryUp e_ConveryLabel = e_Flow_ConveryUp.等待二段治具到位;
        public static e_Flow_Labeling e_LabelingFlow = e_Flow_Labeling.取标签;
        public static e_Flow_Cut e_Cut = e_Flow_Cut.等待有工装到达;
        /// <summary>
        /// 数字匹配
        /// </summary>
        private static string nMatch = "^[0-9]*$";
      
        public static object lockFly = new object();
        public static e_Flow_Fly fly1 = e_Flow_Fly.等待触发飞达;
        public static e_Flow_Fly fly2 = e_Flow_Fly.等待触发飞达;

        public static bool IsDownStart = false;
        public static e_FlowConveryDown e_Down = e_FlowConveryDown.下层等待要料;
        /// <summary>
        /// 复位后刚开机的点检 检查是否有物料
        /// </summary>
        public static void Task_StartCheck()
        {
            try
            {
                if (GlobalVar.isAutoRun)
                {
                    Thread.Sleep(100);
                    var sw = new Stopwatch();
                    sw.Restart();
                    bool isHave = true;
                    while (true)
                    {
                        if (Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] || Input_CardEx2[(int)e_input_extCard2.上输送治具检测3])
                        {
                            isHave = isHave && true;
                        }
                        else
                        {
                            isHave = isHave && false;
                            break;
                        }
                        if (sw.ElapsedMilliseconds > 300)
                        {
                            break;
                        }
                    }
                    if (isHave)
                    {
                        var nCutHave = 0;
                        var nLabelHave = 0;
                        if (Input_CardEx2[(int)e_input_extCard2.上输送治具检测2])//有治具
                        {//撕膜治具
                            Step_ConveryUp(e_Step_ConveryUp.一段治具升起);
                            Thread.Sleep(100);//光纤检测有无产品
                            if (!Input_CardEx2[(int)e_input_extCard2.上输送产品检测1] || !Input_CardEx2[(int)e_input_extCard2.上输送产品检测2])//有一个产品
                                nCutHave = 1;
                            else
                                nCutHave = -1;
                            
                        }

                        if (Input_CardEx2[(int)e_input_extCard2.上输送治具检测3])//有治具
                        {//贴膜治具
                            Step_ConveryUp(e_Step_ConveryUp.二段治具升起);
                            Thread.Sleep(100);
                            if (!Input_CardEx2[(int)e_input_extCard2.上输送产品检测3] || !Input_CardEx2[(int)e_input_extCard2.上输送产品检测4])
                                nLabelHave = 1;
                            else
                                nLabelHave = -1;
                        }

                        if(nCutHave==-1)//有治具无产品
                        {
                            if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] && GlobalVar.isAutoRun)
                            {
                                var msg = "撕膜工位无治具,操作无效";
                                MessageBox.Show(msg);
                                return;
                            }

                            if (GlobalVar.Laser_pros == null || GlobalVar.Laser_pros.Count == 0)
                            {//检测到治具到位，顶起治具
                                GlobalVar.Laser_pros = new List<ProductInfo>();
                                GlobalMotion.Step_ConveryUp(e_Step_ConveryUp.一段治具升起);
                                bool IshavePro1 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测1];
                                bool IshavePro2 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测2];
                                GlobalVar.Laser_pros.Add(new ProductInfo()
                                {
                                    LaserTime = DateTime.Now,
                                    typeName = GlobalVar.closeSave.CurrentTypeName,
                                    ProId = "",
                                    ProNo = 1,
                                    IsProcessAlarm = 1,
                                    Result_up = IshavePro1 ? e_Result.进料OK.ToString() : e_Result.进料读卡NG.ToString(),
                                    Result_Cut = IshavePro1 ? e_Result.撕膜OK.ToString() : e_Result.撕膜NG.ToString(),
                                });
                                GlobalVar.Laser_pros.Add(new ProductInfo()
                                {
                                    LaserTime = DateTime.Now,
                                    typeName = GlobalVar.closeSave.CurrentTypeName,
                                    ProId = "",
                                    ProNo = 2,
                                    IsProcessAlarm = 1,
                                    Result_up = IshavePro2 ? e_Result.进料OK.ToString() : e_Result.进料读卡NG.ToString(),
                                    Result_Cut = IshavePro2 ? e_Result.撕膜OK.ToString() : e_Result.撕膜NG.ToString(),
                                });
                            }
                            GlobalMotion.e_ConveryLaser = e_Flow_ConveryUp.一段治具加工完成;
                        }

                        if (nLabelHave == -1)//有治具无产品
                        {
                            if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送治具检测3] && GlobalVar.isAutoRun)
                            {
                                var msg = "贴标工位无治具,操作无效";
                                MessageBox.Show(msg);
                                return;
                            }
                            if (GlobalVar.Label_pros == null || GlobalVar.Label_pros.Count == 0)
                            {
                                GlobalVar.Label_pros = new List<ProductInfo>();
                                GlobalMotion.Step_ConveryUp(e_Step_ConveryUp.二段治具升起);
                                bool IshavePro3 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测3];
                                bool IshavePro4 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测4];
                                GlobalVar.Label_pros.Add(new ProductInfo()
                                {
                                    LaserTime = DateTime.Now,
                                    typeName = GlobalVar.closeSave.CurrentTypeName,
                                    ProId = "",
                                    ProNo = 1,
                                    IsProcessAlarm = 1,

                                    Result_up = e_Result.进料OK.ToString(),
                                    Result_Label = IshavePro3 ? e_Result.贴膜OK.ToString() : e_Result.贴膜NG.ToString(),
                                    Result_down = IshavePro3 ? e_Result.出料OK.ToString() : e_Result.出料NG.ToString(),
                                });
                                GlobalVar.Label_pros.Add(new ProductInfo()
                                {
                                    LaserTime = DateTime.Now,
                                    typeName = GlobalVar.closeSave.CurrentTypeName,
                                    ProId = "",
                                    ProNo = 2,
                                    IsProcessAlarm = 1,
                                    Result_up = e_Result.进料OK.ToString(),
                                    Result_Label = IshavePro4 ? e_Result.贴膜OK.ToString() : e_Result.贴膜NG.ToString(),
                                    Result_down = IshavePro4 ? e_Result.出料OK.ToString() : e_Result.出料NG.ToString(),
                                });
                            }
                            GlobalMotion.e_ConveryLabel = e_Flow_ConveryUp.二段治具加工完成;
                        }
                        if (nCutHave == 1 || nLabelHave == 1)
                        {
                            GlobalVar.IsTip_Start = true;
                            var curForm = new StartForm();
                            curForm.ShowDialog();
                            GlobalVar.IsTip_Start = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_StartCheck" + ex.Message);
            }
        }

        public static void Task_ConveryDownCheck20240615()
        {
            try
            {
                while (!GlobalVar.isExit)
                {
                    Thread.Sleep(8);
                    if (GlobalVar.userConfig.isEnableDownSignal)
                    {
                        if (!GlobalVar.isEstop)
                        {
                            if (GlobalVar.isAutoRun)
                            {
                                if (GlobalMotion.Input_CardEx2[(int)e_input_extCard2.下输送治具检测1])
                                {
                                    ///输送上有治具
                                    IsDownStart = false;
                                    GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层要料, e_out_OnOff.on);
                                    if (GlobalMotion.Input_Card1[(int)e_input_card1.下层向本机要料])
                                    {
                                        IsDownStart = true;
                                        Thread.Sleep(100);
                                        GlobalMotion.ConveryControrl(e_ConveryControl.下层治具放行, e_MachineStatus.无控制);//放行
                                        Thread.Sleep(GlobalVar.userConfig.DelayCheck_Down);
                                    }
                                    else
                                    {
                                        if (GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送左].m_AxisSts.Motion)
                                            GlobalMotion.ConveryControrl(e_ConveryControl.下层输送停止, e_MachineStatus.无控制);//放行
                                    }
                                }
                                else
                                {
                                    //无治具
                                    GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层物料放行, e_out_OnOff.on);
                                    if (Input_CardEx1[(int)e_input_extCard1.下层阻挡气缸到位1])
                                        GlobalMotion.ConveryControrl(e_ConveryControl.下层治具阻挡, e_MachineStatus.无控制);//阻挡
                                    IsDownStart = true;
                                
                                    Thread.Sleep(GlobalVar.userConfig.DelayCheck_Down);
                                    if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.下输送治具检测1])
                                        GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层要料, e_out_OnOff.off);
                                }
                            }
                            else
                            {
                                   GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层要料, e_out_OnOff.on);
                                if (Input_CardEx1[(ushort)e_input_extCard1.下层阻挡气缸到位1])
                                {
                                    GlobalMotion.ConveryControrl(e_ConveryControl.下层治具阻挡, e_MachineStatus.无控制); ;//放行
                                }
                                IsDownStart = false;
                            }
                        }
                        else
                        {
                            if (Output_Card1[(ushort)e_output_card1.下层要料])
                            {
                                GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层要料, e_out_OnOff.on);
                            }
                            IsDownStart = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_ConveryDownCheck" + ex.Message);
            }
        }
        /// <summary>
        /// 下层等待要料
        /// </summary>
        public static void Task_ConveryDownCheck()
        {
            try
            {
                int nTime = 0;
                var sw_down = new Stopwatch();
                sw_down.Restart();
                while (!GlobalVar.isExit)
                {
                    Thread.Sleep(8);
                    if (GlobalVar.userConfig.isEnableDownSignal)
                    {
                        if (!GlobalVar.isEstop)
                        {
                            if (GlobalVar.isAutoRun)
                            {
                                switch(e_Down)
                                {
                                    case e_FlowConveryDown.下层等待载具到位:
                                        {
                                            GlobalVar.IsTip_down = false;
                                            if (Input_CardEx1[(int)e_input_extCard1.下层阻挡气缸到位1])
                                                GlobalMotion.ConveryControrl(e_ConveryControl.下层治具阻挡, e_MachineStatus.无控制);//阻挡
                                            if (GlobalMotion.Input_CardEx2[(int)e_input_extCard2.下输送治具检测1])
                                            {
                                                #region 确实有载具
                                                var sw = new Stopwatch();
                                                sw.Restart();
                                                bool isOK = true;
                                                while(true)
                                                {
                                                    isOK = isOK && GlobalMotion.Input_CardEx2[(int)e_input_extCard2.下输送治具检测1];
                                                    if (sw.ElapsedMilliseconds>GlobalVar.userConfig.downProTime_In)
                                                    {
                                                        break;
                                                    }
                                                }
                                                #endregion
                                                if (isOK)
                                                {
                                                    IsDownStart = false;
                                                    GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层要料, e_out_OnOff.on);
                                                    e_Down = e_FlowConveryDown.下层等待要料;
                                                }
                                            }
                                            else
                                            {
                                                IsDownStart = true;
                                                GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层物料放行, e_out_OnOff.on);
                                                if (GlobalMotion.Input_Card1[(int)e_input_card1.下层物料OK])
                                                {
                                                    GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层要料, e_out_OnOff.off);
                                                    Thread.Sleep(GlobalVar.userConfig.downDelayArivel);
                                                    break;
                                                }
                                                GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层要料, e_out_OnOff.off);
                                            }
                                          }
                                        break;
                                    case e_FlowConveryDown.下层等待要料:
                                        {
                                            GlobalVar.IsTip_down = false;
                                            IsDownStart = false;
                                            if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.下输送治具检测1])//无载盘在位
                                            {
                                                e_Down = e_FlowConveryDown.下层等待载具到位;
                                                break;
                                            }
                                            if (GlobalMotion.Input_Card1[(int)e_input_card1.下层向本机要料])
                                            {
                                                Thread.Sleep(GlobalVar.userConfig.downDelayBlock);
                                                if (GlobalMotion.Input_Card1[(int)e_input_card1.下层向本机要料])
                                                {
                                                    e_Down = e_FlowConveryDown.下层送料;
                                                    sw_down.Restart();
                                                    break;
                                                }
                                            }
                                        }
                                        break;
                                    case e_FlowConveryDown.下层送料:
                                        {
                                            if(sw_down.ElapsedMilliseconds>GlobalVar.userConfig.downAlarmOut)
                                            {
                                                if(nTime<1)//送两个盘子  第二个盘子卡住送料翘板处理方式
                                                {
                                                    nTime++;
                                                    displalyInfo.displayInfoMain($"下层送料超时 自动处理{nTime}");
                                                    IsDownStart = false;
                                                    Thread.Sleep(100);
                                                    GlobalMotion.ConveryControrl(e_ConveryControl.下层治具阻挡, e_MachineStatus.无控制);//阻挡
                                                    IsDownStart = true;
                                                    Thread.Sleep (GlobalVar.userConfig.downAutoTime);
                                                    e_Down = e_FlowConveryDown.下层等待要料;
                                                    break;
                                                }
                                                IsDownStart = false;
                                                GlobalVar.IsTip_down = true;
                                                MessageBox.Show("下层送料超时  请检查");
                                                Thread.Sleep(1000);
                                                sw_down.Restart();
                                                GlobalVar.IsTip_down = false;
                                                IsDownStart = true;
                                                break;
                                            }
                                            nTime = 0;
                                            IsDownStart = true;
                                            if (GlobalMotion.Input_CardEx2[(int)e_input_extCard2.下输送治具检测1])//有载盘在位
                                            {
                                                GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层物料放行, e_out_OnOff.off);
                                                if (Input_CardEx2[(int)e_input_extCard2.下层阻挡气缸原点1])
                                                    GlobalMotion.ConveryControrl(e_ConveryControl.下层治具放行, e_MachineStatus.无控制);//阻挡
                                                Thread.Sleep(GlobalVar.userConfig.DelayCheck_Down);
                                                #region 确实无载具
                                                var sw = new Stopwatch();
                                                sw.Restart();
                                                bool isOK = true;
                                                while (true)
                                                {
                                                    isOK = isOK && !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.下输送治具检测1];
                                                    if (sw.ElapsedMilliseconds > GlobalVar.userConfig.downProTime_out)
                                                    {
                                                        break;
                                                    }
                                                }
                                                #endregion
                                                if (isOK)//确实无载具
                                                {
                                                    GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层物料放行, e_out_OnOff.on);
                                                    GlobalMotion.ConveryControrl(e_ConveryControl.下层治具阻挡, e_MachineStatus.无控制);//阻挡
                                                    Thread.Sleep(GlobalVar.userConfig.downDelayBlock);
                                                    e_Down = e_FlowConveryDown.下层等待载具到位;
                                                    break;
                                                }
                                            }
                                            else
                                            {
                                                    e_Down = e_FlowConveryDown.下层等待载具到位;
                                                    break;
                                            }
                                        }
                                        break;
                                }
                            }
                        }
                        else
                        {
                            if (Output_Card1[(ushort)e_output_card1.下层要料])
                            {
                                GlobalMotion.Card_1.setOut((ushort)e_output_card1.下层要料, e_out_OnOff.on);
                            }
                            e_Down = e_FlowConveryDown.下层等待要料;
                            IsDownStart = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_ConveryDownCheck" + ex.Message);
            }
        }
        /// <summary>
        /// <summary>
        /// 流程-下层输送
        /// </summary>
        public static void Task_ConveryDown()
        {
            try
            {
                string logFlow = e_ConveryLaser.ToString();
                while (!GlobalVar.isExit)
                {
                    Thread.Sleep(8);
                    if (!GlobalVar.isEstop)
                    {
                        if (IsDownStart)
                        {
                            if (!GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送左].m_AxisSts.Motion && !GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送右].m_AxisSts.Motion)
                                GlobalMotion.ConveryControrl(e_ConveryControl.下层输送启动, e_MachineStatus.无控制);
                        }
                        else
                        {
                            if (GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送左].m_AxisSts.Motion|| GlobalMotion.Card_1.AxisList[(int)e_card1_axis.下层输送右].m_AxisSts.Motion)
                                GlobalMotion.ConveryControrl(e_ConveryControl.下层输送停止, e_MachineStatus.无控制);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_ConveryDown" + ex.Message);
            }
        }
     
     
        //private static int checkString(string boxstring, BoxReadInfo info)
        //{
        //    var isSuccess1 = true;
        //    var isSuccess2 = true;
        //    var isSuccess3 = true;
        //    if (!string.IsNullOrEmpty(info.NGflag) && boxstring.Contains(info.NGflag))//如果包含Ng标记  说明读取没问题
        //        return 1;
        //    if (info.IsCheckNumber)
        //    {
        //        var str_num = boxstring.Substring(info.NumberStart, info.NumberEnd - info.NumberStart);
        //        isSuccess1 = Regex.IsMatch(str_num, nMatch);
        //    }
        //    if (info.IsCheckInclude)
        //    {
        //        int opCount = 0;
        //        for (int i = 0; i < boxstring.Length; i++)
        //        {
        //            if (boxstring[i].ToString() == info.have_O || boxstring[i].ToString() == info.have_P || boxstring[i].ToString() == info.have_R)
        //            {
        //                opCount++;
        //            }
        //        }
        //        isSuccess2 = info.have_OPcount == opCount;
        //        var res = boxstring;
        //        if (!string.IsNullOrEmpty(info.have_O))
        //            res = res.Replace(info.have_O, "");
        //        if (!string.IsNullOrEmpty(info.have_P))
        //            res = res.Replace(info.have_P, "");
        //        if (!string.IsNullOrEmpty(info.have_R))
        //            res = res.Replace(info.have_R, "");
        //        var index = res.IndexOf(info.have_string);
        //        isSuccess3 = index > -1;
        //    }
        //    return isSuccess1 && isSuccess2 && isSuccess3 ? 1 : -1;
        //}
        public static int Step_Manual_Air(e_Manual_Air e_Step, e_platePro e_Plate)
        {
            try
            {
                displalyInfo.displayInfoMain(e_Step.ToString());
                if (GlobalVar.isAutoRun && !GlobalVar.isPause && !GlobalVar.isEstop)
                {
                    displalyInfo.displayInfoMain("自动运行中操作无效");
                    return -1;
                }
                switch (e_Step)
                {

                    case e_Manual_Air.入料段治具阻挡:
                        {
                            GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.上层阻挡气缸1, e_out_OnOff.off);
                        }
                        break;
                    case e_Manual_Air.入料段治具放行:
                        {
                            GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.上层阻挡气缸1, e_out_OnOff.on);
                        }
                        break;
                    case e_Manual_Air.二段治具下降:
                        {
                            GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.上层顶升气缸2, e_out_OnOff.on);
                        }
                        break;
                    case e_Manual_Air.二段治具升起:
                        {
                            GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.上层顶升气缸2, e_out_OnOff.off);
                        }
                        break;
                    case e_Manual_Air.二段治具放行:
                        {
                            GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.上层阻挡气缸3, e_out_OnOff.on);
                        }
                        break;
                    case e_Manual_Air.二段治具阻挡:
                        {
                            GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.上层阻挡气缸3, e_out_OnOff.off);
                        }
                        break;
                    case e_Manual_Air.一段治具下降:
                        {
                            GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.上层顶升气缸1, e_out_OnOff.on);
                        }
                        break;
                    case e_Manual_Air.一段治具升起:
                        {
                            GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.上层顶升气缸1, e_out_OnOff.off);
                        }
                        break;
                    case e_Manual_Air.一段治具放行:
                        {
                            GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.上层阻挡气缸2, e_out_OnOff.on);
                        }
                        break;
                    case e_Manual_Air.一段治具阻挡:
                        {
                            GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.上层阻挡气缸2, e_out_OnOff.off);
                        }
                        break;
                    case e_Manual_Air.NG取工装吸真空:
                        {
                            var e_out = e_out_OnOff.off;
                            if (e_Plate == e_platePro.平台1)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品1, e_out);
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品2, e_out);
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品1, e_out);
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品2, e_out);
                            }
                        }
                        break;
                    case e_Manual_Air.NG放工装破真空:
                        {
                            var e_out = e_out_OnOff.on;
                            if (e_Plate == e_platePro.平台1)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品1, e_out);
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品2, e_out);
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品1, e_out);
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品2, e_out);

                            }
                        }
                        break;
                    case e_Manual_Air.取标气缸抬起:
                        {
                            var e_out = e_out_OnOff.on;
                            if (e_Plate == e_platePro.平台1)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.贴标升降气缸1, e_out);
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.贴标升降气缸2, e_out);
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.贴标升降气缸1, e_out);
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.贴标升降气缸2, e_out);
                            }
                        }
                        break;
                    case e_Manual_Air.取标气缸下压:
                        {
                            var e_out = e_out_OnOff.off;
                            if (e_Plate == e_platePro.平台1)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.贴标升降气缸1, e_out);
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.贴标升降气缸2, e_out);
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.贴标升降气缸1, e_out);
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.贴标升降气缸2, e_out);
                            }
                        }
                        break;
                    case e_Manual_Air.取标签吸真空:
                        {
                            var e_out = e_out_OnOff.off;
                            if (e_Plate == e_platePro.平台1)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.吸标靶面吸气1, e_out);
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.吸标靶面吸气2, e_out);
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.吸标靶面吸气1, e_out);
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.吸标靶面吸气2, e_out);
                            }

                        }
                        break;
                    case e_Manual_Air.放标签破真空:
                        {
                            var e_out = e_out_OnOff.on;
                            if (e_Plate == e_platePro.平台1)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.吸标靶面吸气1, e_out);
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.吸标靶面吸气2, e_out);
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.吸标靶面吸气1, e_out);
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.吸标靶面吸气2, e_out);
                            }
                        }
                        break;
                    case e_Manual_Air.吸标NG下压:
                        {
                            var nok = 1;
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台1取标抬起, false, e_input_extCard1.平台1吸标NG抬起到位, false);
                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台2取标抬起, false, e_input_extCard1.平台2吸标NG抬起到位, false);
                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        var nOK1 = SetAir3(e_output_extCard1.平台1取标抬起, false, e_input_extCard1.平台1吸标NG抬起到位, false);
                                        var nOK2 = SetAir3(e_output_extCard1.平台2取标抬起, false, e_input_extCard1.平台2吸标NG抬起到位, false);
                                        nok = (nOK1 == 1 && nOK2 == 1) ? 1 : -1;
                                    }
                                    break;
                            }
                            return nok;
                        }
                        break;
                    case e_Manual_Air.吸标NG抬起:
                        {
                            var nok = 1;
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台1取标抬起, true, e_input_extCard1.平台1吸标NG抬起到位, true);

                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台2取标抬起, true, e_input_extCard1.平台2吸标NG抬起到位, true);

                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        var nOK1 = SetAir3(e_output_extCard1.平台1取标抬起, true, e_input_extCard1.平台1吸标NG抬起到位, true);
                                        var nOK2 = SetAir3(e_output_extCard1.平台2取标抬起, true, e_input_extCard1.平台2吸标NG抬起到位, true);

                                        nok = (nOK1 == 1 && nOK2 == 1) ? 1 : -1;
                                    }
                                    break;
                            }
                            return nok;
                        }
                        break;
                    case e_Manual_Air.吸标NG吸气:
                        {
                            var nok = 1;
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气1, e_out_OnOff.off);

                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气2, e_out_OnOff.off);
                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气1, e_out_OnOff.off);
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气2, e_out_OnOff.off);
                                    }
                                    break;
                            }
                            Thread.Sleep(GlobalVar.userConfig.deleyNGair);
                            return nok;
                        }
                        break;
                    case e_Manual_Air.吸标NG破气:
                        {
                            var nok = 1;
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气1, e_out_OnOff.on);

                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气2, e_out_OnOff.on);

                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气1, e_out_OnOff.on);
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气2, e_out_OnOff.on);
                                    }
                                    break;
                            }
                            return nok;
                        }
                        break;
                }
                return -1;
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Step_Manual_Air" + ex.Message);
                return -1;
            }
        }
        /// <summary>
        /// 流程-撕膜输送
        /// </summary>
        public static void Task_ConveryCut()///镭雕
        {
            try
            {
                var waitTime = 0;
                var nstop = -1;
                bool isFirst = false;
                string logFlow = e_ConveryLaser.ToString();
                var sw_Leave = new Stopwatch();
                sw_Leave.Restart();
                while (!GlobalVar.isExit)
                {

                    Thread.Sleep(8);
                    if (!GlobalVar.isEstop)
                    {
                        if (GlobalVar.isAutoRun)
                        {
                            if (GlobalVar.IsStart_EndWork)
                            {
                                e_ConveryLaser = e_Flow_ConveryUp.等待一段治具到位;
                                continue;
                            }
                            switch (e_ConveryLaser)
                            {
                                case e_Flow_ConveryUp.等待一段治具到位:
                                    {
                                        if (isFirst)
                                        {
                                            waitTime = 0;
                                            isFirst = false;
                                            #region 暂停控制
                                            nstop = MachineState(e_MachineStatus.暂停控制);
                                            if (nstop != 1)
                                                continue;
                                            #endregion
                                            var nres = Step_ConveryUp(e_Step_ConveryUp.一段治具阻挡);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_ConveryLaser.ToString()}:一段治具阻挡");
                                                continue;
                                            }
                                            
                                        }

                                        var isCutKeep = Input_CardEx2[(int)e_input_extCard2.上输送治具检测2];
                                        var isCutKeep3 = Input_CardEx2[(int)e_input_extCard2.上输送治具检测3];
                                        var isCut1 = Input_CardEx2[(int)e_input_extCard2.上输送产品检测1];
                                        var isCut2 = Input_CardEx2[(int)e_input_extCard2.上输送产品检测2];
                                        if ((GlobalVar.front_pros.Count > 1 && Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] && 
                                            !Input_CardEx2[(int)e_input_extCard2.上输送治具检测1])||
                                            (isCutKeep && isCutKeep3 && e_ConveryLabel == e_Flow_ConveryUp.二段治具加工完成) ||
                                            (isCutKeep  && e_ConveryLabel == e_Flow_ConveryUp.等待二段治具到位))
                                        {
                                            Stopwatch sw = new Stopwatch();
                                            sw.Restart();
                                            
                                            while (true)
                                            {
                                                isCutKeep = isCutKeep && Input_CardEx2[(int)e_input_extCard2.上输送治具检测2];
                                                Thread.Sleep(5);
                                                if (sw.ElapsedMilliseconds > GlobalVar.userConfig.CutKeepTime)
                                                {
                                                    break;
                                                }
                                            }

                                            if (isCutKeep)//在过滤时间里一直都是亮的
                                            {
                                                GlobalVar.StartTime_Cut = DateTime.Now;
                                                if (GlobalVar.Laser_pros.Count == 0&& GlobalVar.front_pros.Count > 0)//等待一段载据处理完
                                                {
                                                    GlobalVar.Laser_pros = GlobalVar.front_pros.Take(2).ToList();
                                                    if (GlobalVar.front_pros.Count > 0)
                                                        GlobalVar.front_pros.Clear();
                                                    waitTime = 0;
                                                    e_ConveryLaser = e_Flow_ConveryUp.一段治具到位;
                                                }
                                                else
                                                {
                                                    //if (GlobalVar.Laser_pros.Count > 0)
                                                    {
                                                        if (waitTime > 6)
                                                        {
                                                            waitTime = 0;
                                                            GlobalVar.Laser_pros.Clear();

                                                            //if (Input_CardEx2[(int)e_input_extCard2.上输送治具检测1])
                                                            {
                                                                GlobalVar.front_pros.Add(new ProductInfo()
                                                                {
                                                                    LaserTime = DateTime.Now,
                                                                    typeName = GlobalVar.closeSave.CurrentTypeName,
                                                                    ProNo = 1,
                                                                    Result_up = e_Result.进料OK.ToString()
                                                                });
                                                                GlobalVar.front_pros.Add(new ProductInfo()
                                                                {
                                                                    LaserTime = DateTime.Now,
                                                                    typeName = GlobalVar.closeSave.CurrentTypeName,
                                                                    ProNo = 2,
                                                                    Result_up = e_Result.进料OK.ToString()
                                                                });
                                                                e_ConveryFront = e_Flow_ConveryUp.入料治具到位;
                                                            }

                                                            break;
                                                        }
                                                        waitTime++;
                                                        displalyInfo.displayInfoMain("撕膜段数据还有缓存  等待撕膜数据处理完");
                                                        Thread.Sleep(500);
                                                    }
                                                }
                                               
                                            }
                                        }
                                        else
                                        {
                                            if (isCutKeep && !isCutKeep3 && e_ConveryLabel == e_Flow_ConveryUp.二段治具加工完成)
                                            {

                                            }
                                        }

                                        if (e_ConveryLabel == e_Flow_ConveryUp.等待二段治具到位)
                                        {

                                        }

                                    }
                                    break;
                                case e_Flow_ConveryUp.一段治具到位:
                                    {

                                        #region 暂停控制
                                        nstop = MachineState(e_MachineStatus.暂停控制);
                                        if (nstop != 1)
                                            continue;
                                        #endregion
                                        if (Input_CardEx2[(int)e_input_extCard2.上输送治具检测2])
                                        {
                                          //  GlobalVar.sw_CT.Restart();
                                            GlobalVar.displayCycleTime_CutReal?.Invoke();

                                            var nres = Step_ConveryUp(e_Step_ConveryUp.一段治具升起);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_ConveryLaser.ToString()}:一段治具升起");
                                                continue;
                                            }
                                            //if (GlobalVar.IsThrought)
                                            //{
                                            //    e_ConveryLaser = e_Flow_ConveryUp.一段治具加工完成;
                                            //    break;
                                            //}
                                            if (!GlobalVar.IsManThrought)
                                            {
                                                GlobalVar.Cut_Start = true;
                                                GlobalVar.Cut_Finish = false;
                                                e_ConveryLaser = e_Flow_ConveryUp.等待一段加工完成;
                                            }
                                            else
                                            {
                                                e_ConveryLaser = e_Flow_ConveryUp.一段治具加工完成;
                                            }
                                        }

                                    }
                                    break;
                                case e_Flow_ConveryUp.等待一段加工完成:
                                    {
                                        ///收到镭雕完成信号
                                        //if (GlobalVar.IsThrought)
                                        //{
                                        //    e_ConveryLaser = e_Flow_ConveryUp.一段治具加工完成;
                                        //    break;
                                        //}
                                        if (GlobalVar.Cut_Finish)
                                            e_ConveryLaser = e_Flow_ConveryUp.一段治具加工完成;

                                    }
                                    break;
                                case e_Flow_ConveryUp.一段治具加工完成:
                                    {
                                        GlobalVar.sw_CT.Stop();
                                        if (!Input_CardEx2[(int)e_input_extCard2.上输送治具检测3] && Input_CardEx1[(int)e_input_extCard1.上层阻挡气缸到位3])//贴标段无料才放行
                                        {
                                            if (e_ConveryLabel != e_Flow_ConveryUp.送料中途下游停止要料)
                                            {
                                                e_ConveryLaser = e_Flow_ConveryUp.一段放行;
                                            }
                                        }
                                    }
                                    break;
                                case e_Flow_ConveryUp.一段放行:
                                    {
                                        GlobalVar.IsAirCut = true;
                                       
                                        var nres = Step_ConveryUp(e_Step_ConveryUp.一段治具放行);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_ConveryLaser.ToString()}:一段治具放行");
                                            continue;
                                        }
                                       
                                        nres = Step_ConveryUp(e_Step_ConveryUp.一段治具下降);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_ConveryLaser.ToString()}:一段治具下降");
                                            continue;
                                        }
                                        Thread.Sleep(GlobalVar.userConfig.delayBlock1);
                                        sw_Leave.Restart();
                                        e_ConveryLaser = e_Flow_ConveryUp.等待一段治具离开;
                                        waitTime = 0;
                                    }
                                    break;
                                case e_Flow_ConveryUp.等待一段治具离开:
                                    {
                                        if(sw_Leave.ElapsedMilliseconds>GlobalVar.userConfig.TimeOut_Leave1)
                                        {
                                            //GlobalVar.isPause = true;
                                            if (GlobalMotion.TipInfo("等待一段治具离开超时  请检查是否卡盘？是：暂停处理     否：继续等待治具离开")==1)
                                            {
                                                sw_Leave.Restart();
                                                 GlobalVar.isPause = false;
                                                //Step_ConveryUp(e_Step_ConveryUp.一段治具下降);
                                                //GlobalMotion.MachineState(e_MachineStatus.暂停控制);
                                                e_ConveryLaser = e_Flow_ConveryUp.一段放行;
                                                break;
                                            }
                                            GlobalVar.isPause = false;
                                            sw_Leave.Restart();
                                        }

                                        bool eX2 = Input_CardEx2[(int)e_input_extCard2.上输送治具检测2];
                                        bool eX3 = Input_CardEx2[(int)e_input_extCard2.上输送治具检测3];
                                        bool isSx2 = Input_CardEx1[(int)e_input_extCard1.上层阻挡气缸到位2];
                                        if (!eX3)
                                        {
                                            GlobalMotion.Card_1.setOut((ushort)e_output_card1.上层向上游要料, e_out_OnOff.on);
                                            Step_ConveryUp(e_Step_ConveryUp.一段治具放行);
                                        }

                                        if (!Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] && !Input_CardEx1[(int)e_input_extCard1.上层阻挡气缸到位2])
                                        {
                                            var nres = Step_ConveryUp(e_Step_ConveryUp.一段治具阻挡);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_ConveryLaser.ToString()}:一段治具阻挡");
                                                break;
                                            }
                                        }
                                        if (!Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] && Input_CardEx2[(int)e_input_extCard2.上输送治具检测3])//贴标段无料才放行
                                        {
                                            GlobalVar.displayCycleTime_Cut?.Invoke();

                                            isFirst = true;
                                            if (GlobalVar.Laser_pros.Count > 1 && GlobalVar.Label_pros.Count == 0)///确定数据没问题再出队列
                                            {
                                                GlobalVar.Label_pros = GlobalVar.Laser_pros.Take(2).ToList();
                                                GlobalVar.Laser_pros.Clear();
                                              
                                                e_ConveryLaser = e_Flow_ConveryUp.等待一段治具到位;
                                            }
                                            else
                                            {
                                                if(GlobalVar.Label_pros.Count > 0)
                                                {
                                                    if (waitTime > 6)
                                                    {
                                                        //MachineState(e_MachineStatus.异常急停, "等待贴文字版段数据处理  超时");
                                                        e_ConveryLaser = e_Flow_ConveryUp.等待一段治具到位;
                                                        break;
                                                    }
                                                    waitTime++;
                                                    displalyInfo.displayInfoMain("贴文字版段数据还有缓存  等待贴文字版段数据处理完");
                                                    Thread.Sleep(2000);
                                                    break;
                                                }
                                            }
                                           
                                        }
                                        else
                                        {
                                            if ( !Input_CardEx2[(int)e_input_extCard2.上输送治具检测3]||
                                                (Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] && Input_CardEx2[(int)e_input_extCard2.上输送治具检测3]))
                                            {
                                                GlobalVar.Label_pros = GlobalVar.Laser_pros.Take(2).ToList();
                                                GlobalVar.Laser_pros.Clear();

                                                e_ConveryLaser = e_Flow_ConveryUp.等待一段治具到位;
                                            }
                                        }
                                    }
                                    break;
                            }
                            if (logFlow != e_ConveryLaser.ToString())
                            {
                                logFlow = e_ConveryLaser.ToString();
                                displalyInfo.displayInfoMain(logFlow);
                            }
                        }
                        else
                            isFirst = true;
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_ConveryLaser" + ex.Message);
            }

        }

        /// <summary>
        /// 流程-贴标输送 从一工位流动到贴膜位置
        /// </summary>
        public static void Task_ConveryLabel()///贴标
        {
            try
            {
                var sw_realse = new Stopwatch();
                sw_realse.Restart();
                string logFlow = e_ConveryLabel.ToString();
                var nstop = -1;
                bool isFirst = true;
                var waitStop = new Stopwatch();
                int counter = 0;

                while (!GlobalVar.isExit)
                {

                    Thread.Sleep(8);
                    if (!GlobalVar.isEstop)
                    {
                        if (GlobalVar.isAutoRun)
                        {                            
                            if (GlobalVar.IsStart_EndWork)
                            {
                                e_ConveryLabel = e_Flow_ConveryUp.等待二段治具到位;
                                continue;
                            }
                            switch (e_ConveryLabel)
                            {
                                case e_Flow_ConveryUp.等待二段治具到位:
                                    {

                                        if (isFirst)
                                        {
                                            var nres = Step_ConveryUp(e_Step_ConveryUp.二段治具阻挡);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_ConveryLabel.ToString()}:二段治具阻挡");
                                                continue;
                                            }
                                            isFirst = false;
                                            sw_realse.Restart();
                                        }

                                        bool isEx1 = Input_CardEx2[(int)e_input_extCard2.上输送治具检测1];
                                        bool isEx2 = Input_CardEx2[(int)e_input_extCard2.上输送治具检测2];
                                        bool isEx3 = Input_CardEx2[(int)e_input_extCard2.上输送治具检测3];
                                        bool isEx4 = Input_CardEx2[(int)e_input_extCard2.上层阻挡气缸原点2];

                                        if (isEx3)
                                        {
                                            bool IshavePro3 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测3];
                                            bool IshavePro4 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测4];

                                            if (GlobalVar.Label_pros.Count > 0)
                                            {
                                                var nres = Step_ConveryUp(e_Step_ConveryUp.二段治具阻挡);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_ConveryLabel.ToString()}:二段治具阻挡");
                                                    continue;
                                                }
                                                e_ConveryLabel = e_Flow_ConveryUp.二段治具到位;
                                            }
                                            else
                                            {
                                                if (sw_realse.ElapsedMilliseconds > 8000)
                                                {
                                                    displalyInfo.displayInfoMain("贴标工位治具检测失败");
                                                    sw_realse.Restart();

                                                    GlobalVar.Label_pros.Clear();
                                                    GlobalVar.Label_pros.Add(new ProductInfo()
                                                    {
                                                        LaserTime = DateTime.Now,
                                                        typeName = GlobalVar.closeSave.CurrentTypeName,
                                                        ProId = "O1",
                                                        ProNo = 1,
                                                        IsProcessAlarm = 1,

                                                        Result_up = e_Result.进料OK.ToString(),
                                                        Result_Label = IshavePro3 ? e_Result.贴膜OK.ToString() : e_Result.贴膜NG.ToString(),
                                                        Result_down = IshavePro3 ? e_Result.出料OK.ToString() : e_Result.出料NG.ToString(),
                                                    });
                                                    GlobalVar.Label_pros.Add(new ProductInfo()
                                                    {
                                                        LaserTime = DateTime.Now,
                                                        typeName = GlobalVar.closeSave.CurrentTypeName,
                                                        ProId = "O1",
                                                        ProNo = 2,
                                                        IsProcessAlarm = 1,
                                                        Result_up = e_Result.进料OK.ToString(),
                                                        Result_Label = IshavePro4 ? e_Result.贴膜OK.ToString() : e_Result.贴膜NG.ToString(),
                                                        Result_down = IshavePro4 ? e_Result.出料OK.ToString() : e_Result.出料NG.ToString(),
                                                    });
                                                    e_ConveryLabel = e_Flow_ConveryUp.二段治具到位;
                                                    GlobalVar.isPause = false;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (!isEx1 && !isEx2 && !isEx3 && !isFirst)
                                            {
                                                //Step_ConveryUp(e_Step_ConveryUp.一段治具放行);
                                            }
                                            sw_realse.Restart();
                                        }

                                    }
                                    break;
                                case e_Flow_ConveryUp.二段治具到位:
                                    {
                                        if (Input_CardEx2[(int)e_input_extCard2.上输送治具检测3])
                                        {
                                            GlobalVar.sw_CT2.Restart();
                                            GlobalVar.displayCycleTime_LabelReal?.Invoke();
                                            Thread.Sleep(GlobalVar.userConfig.delayLift2);
                                            if (Input_CardEx2[(int)e_input_extCard2.上输送治具检测3])
                                            {
                                                var nres = Step_ConveryUp(e_Step_ConveryUp.二段治具升起);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_ConveryLabel.ToString()}:二段治具升起");
                                                    continue;
                                                }
                                                //if (GlobalVar.IsThrought)
                                                //{
                                                //    e_ConveryLabel = e_Flow_ConveryUp.二段治具加工完成;
                                                //    break;
                                                //}
                                                if (!GlobalVar.IsManThrought)
                                                {
                                                    GlobalVar.LabelFinshed = false;
                                                    ///发送开始贴标信号
                                                    GlobalVar.Label_Start = true;

                                                }
                                                else
                                                {
                                                    GlobalVar.isManFinish = false;
                                                    GlobalVar.isMan_Start = true;
                                                }
                                                e_ConveryLabel = e_Flow_ConveryUp.等待二段加工完成;
                                                //if (GlobalVar.IsThrought)
                                                //    e_ConveryLabel = e_Flow_ConveryUp.二段治具加工完成;
                                            }
                                        }
                                    }
                                    break;
                                case e_Flow_ConveryUp.等待二段加工完成:
                                    {
                                        //if (GlobalVar.IsThrought)
                                        //{
                                        //    e_ConveryLabel = e_Flow_ConveryUp.二段治具加工完成;
                                        //    break;
                                        //}
                                        if (GlobalVar.LabelFinshed)
                                        {
                                            sw_realse.Restart();
                                            GlobalVar.LabelFinshed = false;
                                            e_ConveryLabel = e_Flow_ConveryUp.二段治具加工完成;
                                        }
                                        if (GlobalVar.isManFinish)
                                        {
                                            sw_realse.Restart();
                                            GlobalVar.isManFinish = false;
                                            e_ConveryLabel = e_Flow_ConveryUp.二段治具加工完成;
                                        }

                                        ///收到贴标完成信号
                                    }
                                    break;
                                case e_Flow_ConveryUp.二段治具加工完成:
                                    {
                                        GlobalVar.sw_CT2.Stop();
                                        if (GlobalVar.userConfig.isEnableUpSignal)
                                        {
                                            if (!GlobalVar.IsRealsePro && !GlobalMotion.Input_Card1[(int)e_input_card1.上层向本机要料])
                                            {
                                                if (sw_realse.ElapsedMilliseconds > 10000)
                                                {
                                                    displalyInfo.displayInfoMain("等待上层向本机要料");
                                                    sw_realse.Restart();
                                                }
                                                break;
                                            }
                                            else
                                            {
                                                displalyInfo.displayInfoMain("收到上层向本机要料");
                                                e_ConveryLabel = e_Flow_ConveryUp.二段写入信息与放行;
                                            }
                                        }

                                    }
                                    break;
                                case e_Flow_ConveryUp.二段写入信息与放行:
                                    {
                                        GlobalVar.IsRealsePro = false;
                                        var RFIDinfo = GlobalVar.userConfig.RFIDBox;

                                        var arrCheck = new string[2] { "", "" };
                                        var arrSource = new string[2] { "", "" };
                                        var resRfid_temp = GlobalVar.RFIDBox_out.ReadRFID("P3", GlobalVar.motionConfig.rfid_mode);

                                        for (int i = 0; i < GlobalVar.Label_pros.Count; i++)
                                        {
                                            #region 老RFID
                                            //if (!RFIDinfo.IsEnableRFID)
                                            //{
                                            //    var boxInfo = GlobalVar.motionConfig.boxReadInfo;
                                            //    if (boxInfo.IsEnable)
                                            //    {
                                            //        var checkTime = 5;
                                            //        if (GlobalVar.Label_pros[i].Result_Label.Contains(e_Result.贴膜OK.ToString()) && !GlobalVar.Label_pros[i].Result_up.Contains("NG"))
                                            //        {
                                            //            var addstr = boxInfo.OK;
                                            //            if (GlobalVar.Label_pros[i].IsProcessAlarm == 1)
                                            //                addstr = boxInfo.NGOK;
                                            //            if (GlobalVar.IsManThrought)
                                            //                addstr = boxInfo.MR;
                                            //            var res = "";

                                            //            if (GlobalVar.Label_pros[i].ProNo == 1)
                                            //            {
                                            //                if (GlobalVar.Label_pros[i].ProId == null || GlobalVar.Label_pros[i].ProId.Length <= boxInfo.minLength)
                                            //                {
                                            //                    if (GlobalVar.Label_pros[i].Result_up != e_Result.进料读卡NG.ToString())
                                            //                    {
                                            //                        var pro1 = GlobalVar.Box2.ReadBoxString(boxInfo.StartAddress1, boxInfo.dataLength, boxInfo.station, boxInfo.IsReadWriteOK, boxInfo.nTimes);
                                            //                        displalyInfo.displayInfoMain($"出料读卡器再读一次B产品内容为{pro1}");
                                            //                        GlobalVar.Label_pros[i].ProId = pro1;
                                            //                    }
                                            //                }
                                            //                if (GlobalVar.Label_pros[i].ProId == null || GlobalVar.Label_pros[i].ProId.Length <= boxInfo.minLength)
                                            //                {
                                            //                    displalyInfo.displayErrorMain($"B产品内容太短不进行写入");
                                            //                }
                                            //                else
                                            //                {
                                            //                    for (int r = 0; r < checkTime; r++)
                                            //                    {

                                            //                        var str_result = GlobalVar.Label_pros[i].ProId + addstr;
                                            //                        displalyInfo.displayInfoMain($"写入读卡器1产品内容为{str_result}第{r + 1}次");
                                            //                        res = GlobalVar.Box2.WriteBoxString(boxInfo.StartAddress1, str_result, boxInfo.station, boxInfo.IsReadWriteOK);
                                            //                        Application.DoEvents();
                                            //                        Thread.Sleep(50);
                                            //                        var proRead = GlobalVar.Box2.ReadBoxString(boxInfo.StartAddress1, str_result.Length, boxInfo.station, boxInfo.IsReadWriteOK, boxInfo.nTimes);
                                            //                        if (proRead.Replace(" ", "").Replace("\0", "") == str_result)
                                            //                        {
                                            //                            displalyInfo.displayInfoMain($"写入读卡器1产品内容验证成功{proRead}");
                                            //                            break;
                                            //                        }
                                            //                        else
                                            //                        {

                                            //                            displalyInfo.displayErrorMain($"写入读卡器1产品内容验证失败{proRead}");
                                            //                        }

                                            //                    }
                                            //                }
                                            //            }
                                            //            else if (GlobalVar.Label_pros[i].ProNo == 2)
                                            //            {

                                            //                if (GlobalVar.Label_pros[i].ProId == null || GlobalVar.Label_pros[i].ProId.Length <= boxInfo.minLength)
                                            //                {
                                            //                    if (GlobalVar.Label_pros[i].Result_up != e_Result.进料读卡NG.ToString())
                                            //                    {
                                            //                        var pro2 = GlobalVar.Box2.ReadBoxString(boxInfo.StartAddress2, boxInfo.dataLength, boxInfo.station, boxInfo.IsReadWriteOK);
                                            //                        displalyInfo.displayInfoMain($"出料读卡器再读一次B产品内容为{pro2}");
                                            //                        GlobalVar.Label_pros[i].ProId = pro2;
                                            //                    }
                                            //                }
                                            //                if (GlobalVar.Label_pros[i].ProId == null || GlobalVar.Label_pros[i].ProId.Length <= boxInfo.minLength)
                                            //                {
                                            //                    displalyInfo.displayErrorMain($"A产品内容太短不进行写入");
                                            //                }
                                            //                else
                                            //                {
                                            //                    for (int r = 0; r < checkTime; r++)
                                            //                    {
                                            //                        var str_result = GlobalVar.Label_pros[i].ProId + addstr;
                                            //                        displalyInfo.displayInfoMain($"写入读卡器2产品内容为{str_result}第{r + 1}次");
                                            //                        res = GlobalVar.Box2.WriteBoxString(boxInfo.StartAddress2, str_result, boxInfo.station, boxInfo.IsReadWriteOK);
                                            //                        Application.DoEvents();
                                            //                        Thread.Sleep(50);
                                            //                        var proRead = GlobalVar.Box2.ReadBoxString(boxInfo.StartAddress2, str_result.Length, boxInfo.station, boxInfo.IsReadWriteOK);
                                            //                        if (proRead == str_result)
                                            //                        {
                                            //                            displalyInfo.displayInfoMain($"写入读卡器2产品内容验证成功{proRead}");
                                            //                            break;
                                            //                        }
                                            //                        else
                                            //                        {

                                            //                            displalyInfo.displayErrorMain($"写入读卡器2产品内容验证失败{proRead}");
                                            //                        }

                                            //                    }
                                            //                }
                                            //            }
                                            //            if (res == "OK")
                                            //            {
                                            //                GlobalVar.Label_pros[i].Result = GlobalVar.Label_pros[i].ProId + addstr + e_Result.写入读卡器OK.ToString();
                                            //                GlobalVar.Label_pros[i].Result_down = e_Result.出料OK.ToString();
                                            //            }
                                            //            else
                                            //            {
                                            //                GlobalVar.Label_pros[i].Result = GlobalVar.Label_pros[i].ProId + addstr + e_Result.写入读卡器NG.ToString();
                                            //                GlobalVar.Label_pros[i].Result_down = e_Result.出料NG.ToString();
                                            //            }
                                            //        }
                                            //        else
                                            //        {
                                            //            var addstr = boxInfo.NGNG;
                                            //            var res = "";
                                            //            if (GlobalVar.Label_pros[i].ProNo == 1)
                                            //            {
                                            //                if (GlobalVar.Label_pros[i].ProId == null || GlobalVar.Label_pros[i].ProId.Length <= boxInfo.minLength)
                                            //                {
                                            //                    var pro1 = "";
                                            //                    for (int n = 0; n < boxInfo.nTimes; n++)
                                            //                    {
                                            //                        pro1 = GlobalVar.Box2.ReadBoxString(boxInfo.StartAddress1, boxInfo.dataLength, boxInfo.station, boxInfo.IsReadWriteOK);
                                            //                        displalyInfo.displayInfoMain($"出料读卡器再读一次产品B内容为{pro1}");
                                            //                        if (pro1 != null && pro1.Length >= boxInfo.minLength)
                                            //                            break;
                                            //                    }

                                            //                    GlobalVar.Label_pros[i].ProId = pro1;
                                            //                }
                                            //                if (GlobalVar.Label_pros[i].ProId == null || GlobalVar.Label_pros[i].ProId.Length <= boxInfo.minLength)
                                            //                {
                                            //                    displalyInfo.displayErrorMain($"B产品内容太短不进行写入");
                                            //                }
                                            //                else
                                            //                {
                                            //                    for (int r = 0; r < checkTime; r++)
                                            //                    {

                                            //                        if (!GlobalVar.Label_pros[i].ProId.Contains(boxInfo.NGflag))
                                            //                        {
                                            //                            var str_result = GlobalVar.Label_pros[i].ProId + addstr;
                                            //                            displalyInfo.displayInfoMain($"写入读卡器1产品内容为{str_result}第{r + 1}次");
                                            //                            res = GlobalVar.Box2.WriteBoxString(boxInfo.StartAddress1, str_result, boxInfo.station, boxInfo.IsReadWriteOK);
                                            //                            Application.DoEvents();
                                            //                            Thread.Sleep(50);
                                            //                            var proRead = GlobalVar.Box2.ReadBoxString(boxInfo.StartAddress1, str_result.Length, boxInfo.station, boxInfo.IsReadWriteOK);
                                            //                            if (proRead == str_result)
                                            //                            {
                                            //                                displalyInfo.displayInfoMain($"写入读卡器1产品内容验证成功{proRead}");
                                            //                                break;
                                            //                            }
                                            //                            else
                                            //                            {

                                            //                                displalyInfo.displayErrorMain($"写入读卡器1产品内容验证失败{proRead}");
                                            //                            }
                                            //                        }
                                            //                        else
                                            //                        {
                                            //                            addstr = "";
                                            //                        }
                                            //                    }
                                            //                }
                                            //            }
                                            //            else if (GlobalVar.Label_pros[i].ProNo == 2)
                                            //            {

                                            //                if (GlobalVar.Label_pros[i].ProId == null || GlobalVar.Label_pros[i].ProId.Length <= boxInfo.minLength)
                                            //                {
                                            //                    var pro2 = "";
                                            //                    for (int n = 0; n < boxInfo.nTimes; n++)
                                            //                    {
                                            //                        pro2 = GlobalVar.Box2.ReadBoxString(boxInfo.StartAddress2, boxInfo.dataLength, boxInfo.station, boxInfo.IsReadWriteOK);
                                            //                        displalyInfo.displayInfoMain($"出料读卡器再读一次产品A内容为{pro2}");
                                            //                        if (pro2 != null && pro2.Length >= boxInfo.minLength)
                                            //                            break;
                                            //                    }
                                            //                    GlobalVar.Label_pros[i].ProId = pro2;
                                            //                }
                                            //                if (GlobalVar.Label_pros[i].ProId == null || GlobalVar.Label_pros[i].ProId.Length <= boxInfo.minLength)
                                            //                {
                                            //                    displalyInfo.displayErrorMain($"A产品内容太短不进行写入");
                                            //                }
                                            //                else
                                            //                {
                                            //                    for (int r = 0; r < checkTime; r++)
                                            //                    {
                                            //                        if (!GlobalVar.Label_pros[i].ProId.Contains(boxInfo.NGflag))
                                            //                        {
                                            //                            var str_result = GlobalVar.Label_pros[i].ProId + addstr;
                                            //                            displalyInfo.displayInfoMain($"写入读卡器2产品内容为{str_result}第{r + 1}次");
                                            //                            res = GlobalVar.Box2.WriteBoxString(boxInfo.StartAddress2, str_result, boxInfo.station, boxInfo.IsReadWriteOK);
                                            //                            Application.DoEvents();
                                            //                            Thread.Sleep(50);
                                            //                            var proRead = GlobalVar.Box2.ReadBoxString(boxInfo.StartAddress2, str_result.Length, boxInfo.station, boxInfo.IsReadWriteOK);
                                            //                            if (proRead == str_result)
                                            //                            {
                                            //                                displalyInfo.displayInfoMain($"写入读卡器2产品内容验证成功{proRead}");
                                            //                                break;
                                            //                            }
                                            //                            else
                                            //                                displalyInfo.displayErrorMain($"写入读卡器2产品内容验证失败{proRead}");
                                            //                        }
                                            //                        else
                                            //                        {
                                            //                            addstr = "";
                                            //                        }
                                            //                    }
                                            //                }
                                            //            }
                                            //            if (res == "OK")
                                            //            {
                                            //                GlobalVar.Label_pros[i].Result = GlobalVar.Label_pros[i].ProId + addstr + e_Result.写入读卡器OK.ToString();
                                            //            }
                                            //            else
                                            //            {
                                            //                GlobalVar.Label_pros[i].Result = GlobalVar.Label_pros[i].ProId + addstr + e_Result.写入读卡器NG.ToString();
                                            //            }
                                            //            GlobalVar.Label_pros[i].Result_down = e_Result.出料NG.ToString();
                                            //        }
                                            //    }
                                            //}
                                            //else
                                            #endregion
                                            {
                                                if (RFIDinfo.IsEnable)
                                                {
                                                    var addstr = RFIDinfo.NGNG;
                                                    if (GlobalVar.Label_pros[i].Result_Label.Contains(e_Result.贴膜OK.ToString()))
                                                    {
                                                        addstr = RFIDinfo.OK;
                                                        if (GlobalVar.Label_pros[i].IsProcessAlarm == 1)
                                                            addstr = RFIDinfo.NGOK;
                                                        if (GlobalVar.IsManThrought && !GlobalVar.IsThrought)
                                                            addstr = RFIDinfo.MR;
                                                        if (GlobalVar.IsManThrought && GlobalVar.IsThrought)
                                                            addstr = RFIDinfo.MR_Auto;
                                                        GlobalVar.Label_pros[i].Result_down = e_Result.出料OK.ToString();
                                                    }
                                                    else
                                                    {
                                                        GlobalVar.Label_pros[i].Result_down = e_Result.出料NG.ToString();
                                                    }
                                                    var res = "";
                                              //      if (!string.IsNullOrEmpty(GlobalVar.Label_pros[i].ProId) && !GlobalVar.Label_pros[i].ProId.Contains(RFIDinfo.NGflag))
                                                    {
                                                        
                                                        if (GlobalVar.Label_pros[i].ProNo == 1)
                                                        {
                                                            if (string.IsNullOrEmpty(GlobalVar.Label_pros[i].ProId) || GlobalVar.Label_pros[i].ProId.Length <= 5)
                                                            {
                                                                if (GlobalVar.Label_pros[i].Result_up != e_Result.进料读卡NG.ToString())
                                                                {
                                                                    //var resRfid_temp = GlobalVar.RFIDBox_out.ReadRFID("P3", GlobalVar.motionConfig.rfid_mode);
                                                                    if (resRfid_temp != null && resRfid_temp.arr_Rfid != null && resRfid_temp.arr_Rfid.Length == 2 )
                                                                    {
                                                                        var pro1 = resRfid_temp.arr_Rfid[(int)e_RFIDPlate.产品1];
                                                                        displalyInfo.displayInfoMain($"出料读卡器再读一次B产品内容为{pro1}");
                                                                        GlobalVar.Label_pros[i].ProId = pro1;
                                                                        if (resRfid_temp.Check_state != null && resRfid_temp.Check_state.Length == 2)
                                                                        {
                                                                            if (!resRfid_temp.Check_state[(int)e_RFIDPlate.产品1])
                                                                                addstr = RFIDinfo.NGNG;
                                                                            else
                                                                            {
                                                                                var msg_Rfid = $"出料读卡器1:{pro1} ";
                                                                                var resRfid_clear = GlobalVar.RFIDBox_out.ReadRFID_Clear(new string[] { pro1, pro1 });
                                                                                if (resRfid_clear != null && resRfid_clear.isClear)
                                                                                {
                                                                                    GlobalVar.IsEndWork = true;
                                                                                    msg_Rfid += "结束作业";
                                                                                }
                                                                                displalyInfo.displayInfoMain(msg_Rfid);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }

                                                            if (!string.IsNullOrEmpty(GlobalVar.Label_pros[i].ProId) && GlobalVar.Label_pros[i].ProId.Contains(RFIDinfo.NGNG) && addstr == RFIDinfo.NGNG)
                                                                addstr = "";
                                                            arrSource[(int)e_RFIDPlate.产品1] = GlobalVar.Label_pros[i].ProId;
                                                            arrCheck[(int)e_RFIDPlate.产品1] = addstr;
                                                            var str_Write = GlobalVar.Label_pros[i].ProId + addstr;
                                                            if (str_Write.Contains(RFIDinfo.OK))
                                                                str_Write = str_Write.Replace(RFIDinfo.OK, RFIDinfo.station);
                                                            //string proId_Out = "";
                                                            //var resRfid = GlobalVar.RFIDBox_out.WriteRFID(RFIDinfo.station, arrCheck, arrSource);
                                                            //for (int c = 0; c < RFIDinfo.nWriteTimes; c++)
                                                            //{
                                                            //    if (resRfid.arr_Rfid != null && resRfid.arr_Rfid.Length == 2)
                                                            //    {
                                                            //        if (!string.IsNullOrEmpty(resRfid.arr_Rfid[(int)e_RFIDPlate.产品1]) && resRfid.arr_Rfid[(int)e_RFIDPlate.产品1].IndexOf(GlobalVar.Label_pros[i].ProId) > -1 && string.IsNullOrEmpty(resRfid.msg))
                                                            //        {
                                                            //            res = "OK";
                                                            //            proId_Out = resRfid.arr_Rfid[(int)e_RFIDPlate.产品1];
                                                            //            displalyInfo.displayInfoMain($"出料读卡器产品1内容校验成功{proId_Out }");
                                                            //            break;
                                                            //        }
                                                            //        else
                                                            //        {
                                                            //            proId_Out = resRfid.arr_Rfid[(int)e_RFIDPlate.产品1];
                                                            //            displalyInfo.displayInfoMain($"出料读卡器产品1内容{proId_Out}校验失败，第{c + 1}次  再次写入{str_Write}");
                                                            //            resRfid = GlobalVar.RFIDBox_out.WriteRFID(RFIDinfo.station, arrCheck, arrSource);
                                                            //        }
                                                            //    }
                                                            //    else
                                                            //    {
                                                            //        displalyInfo.displayInfoMain($"出料读卡器产品1内容校验失败，第{c + 1}次  再次写入{str_Write}");
                                                            //        resRfid = GlobalVar.RFIDBox_out.WriteRFID(RFIDinfo.station, arrCheck, arrSource);
                                                            //    }
                                                            //}
                                                            GlobalVar.Label_pros[i].ProId_out = resRfid_temp.arr_Rfid[(int)e_RFIDPlate.产品1]+ str_Write;
                                                        }

                                                        if (GlobalVar.Label_pros[i].ProNo == 2)
                                                        {
                                                            if (string.IsNullOrEmpty(GlobalVar.Label_pros[i].ProId) || GlobalVar.Label_pros[i].ProId.Length <= 5)
                                                            {
                                                                if (GlobalVar.Label_pros[i].Result_up != e_Result.进料读卡NG.ToString())
                                                                {
                                                                    //var resRfid_temp = GlobalVar.RFIDBox_out.ReadRFID("P3", GlobalVar.motionConfig.rfid_mode);
                                                                    if (resRfid_temp != null && resRfid_temp.arr_Rfid != null && resRfid_temp.arr_Rfid.Length == 2 )
                                                                    {
                                                                        var pro2 = resRfid_temp.arr_Rfid[(int)e_RFIDPlate.产品2];
                                                                        displalyInfo.displayInfoMain($"出料读卡器再读一次A产品内容为{pro2}");
                                                                        GlobalVar.Label_pros[i].ProId = pro2;
                                                                        if (resRfid_temp.Check_state != null && resRfid_temp.Check_state.Length == 2)
                                                                        {
                                                                            if (!resRfid_temp.Check_state[(int)e_RFIDPlate.产品2])
                                                                                addstr = RFIDinfo.NGNG;
                                                                            else
                                                                            {
                                                                                var msg_Rfid = $"出料读卡器2:{pro2} ";
                                                                                var resRfid_clear = GlobalVar.RFIDBox_out.ReadRFID_Clear(new string[] { pro2, pro2 });
                                                                                if (resRfid_clear != null && resRfid_clear.isClear)
                                                                                {
                                                                                    GlobalVar.IsEndWork = true;
                                                                                    msg_Rfid += "结束作业";
                                                                                }
                                                                                displalyInfo.displayInfoMain(msg_Rfid);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            //var arrCheck = new string[2] { "", "" };
                                                            //var arrSource = new string[2] { "", "" };
                                                            if (!string.IsNullOrEmpty(GlobalVar.Label_pros[i].ProId) && GlobalVar.Label_pros[i].ProId.Contains(RFIDinfo.NGNG) && addstr == RFIDinfo.NGNG)
                                                                addstr = "";
                                                            arrCheck[(int)e_RFIDPlate.产品2] = addstr;
                                                            arrSource[(int)e_RFIDPlate.产品2] = GlobalVar.Label_pros[i].ProId;
                                                            var str_Write = GlobalVar.Label_pros[i].ProId + addstr;
                                                            string proId_Out = "";
                                                            if (str_Write.Contains(RFIDinfo.OK))
                                                                str_Write = str_Write.Replace(RFIDinfo.OK, RFIDinfo.station);
                                                            var resRfid = GlobalVar.RFIDBox_out.WriteRFID(RFIDinfo.station, arrCheck, arrSource);
                                                            for (int c = 0; c < RFIDinfo.nWriteTimes; c++)
                                                            {
                                                                if (resRfid.arr_Rfid != null && resRfid.arr_Rfid.Length == 2)
                                                                {
                                                                    if (!string.IsNullOrEmpty(resRfid.arr_Rfid[(int)e_RFIDPlate.产品2]) && resRfid.arr_Rfid[(int)e_RFIDPlate.产品2].IndexOf(GlobalVar.Label_pros[i].ProId) > -1 && string.IsNullOrEmpty(resRfid.msg))
                                                                    {
                                                                        res = "OK";
                                                                        proId_Out = resRfid.arr_Rfid[(int)e_RFIDPlate.产品2];
                                                                        displalyInfo.displayInfoMain($"出料读卡器产品2内容校验成功{proId_Out }");
                                                                        break;
                                                                    }
                                                                    else
                                                                    {
                                                                        proId_Out = resRfid.arr_Rfid[(int)e_RFIDPlate.产品2];
                                                                        displalyInfo.displayInfoMain($"出料读卡器产品2内容{proId_Out}校验失败，第{c + 1}次  再次写入{str_Write}");
                                                                        resRfid = GlobalVar.RFIDBox_out.WriteRFID(RFIDinfo.station, arrCheck, arrSource);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    displalyInfo.displayInfoMain($"出料读卡器产品2内容校验失败，第{c + 1}次  再次写入{str_Write}");
                                                                    resRfid = GlobalVar.RFIDBox_out.WriteRFID(RFIDinfo.station, arrCheck, arrSource);
                                                                    
                                                                }
                                                            }
                                                            GlobalVar.Label_pros[i].ProId_out = proId_Out;
                                                            //GlobalVar.Label_pros[0].ProId_out = resRfid.arr_Rfid[(int)e_RFIDPlate.产品1];
                                                        }
                                                    }

                                                    if (res == "OK")
                                                    {
                                                        //counter =0;
                                                        GlobalVar.Label_pros[i].Result = GlobalVar.Label_pros[i].ProId + addstr + e_Result.写入读卡器OK.ToString();
                                                    }
                                                    else
                                                    {
                                                        GlobalVar.Label_pros[i].Result = GlobalVar.Label_pros[i].ProId + addstr + e_Result.写入读卡器NG.ToString();
                                                        //if (counter > 15)
                                                        //{
                                                        //    counter = 0;
                                                        //    //GlobalMotion.TipInfo("Rfid NG 累计数量过多，请检查！");
                                                        //}
                                                        //else
                                                        //{
                                                        //    counter++;
                                                        //}
                                                    }
                                                }
                                            }
                                            GlobalVar.Label_pros[i].LabelTime = DateTime.Now;
                                            displalyInfo.addInfoRow(GlobalVar.Label_pros[i]);
                                        }

                                        if (GlobalVar.userConfig.IgnoreFrontSignal)
                                        {
                                            GlobalVar.Label_pros.Clear();
                                            if (GlobalVar.userConfig.isEnableUpSignal)
                                                GlobalMotion.Card_1.setOut((ushort)e_output_card1.上层物料OK, e_out_OnOff.off);
                                        }
                                        else
                                        {
                                            if (GlobalVar.Label_pros.Where(a => a.Result_down.Contains("NG")).Count() > 1)
                                            {
                                                GlobalVar.Label_pros.Clear();
                                                if (GlobalVar.userConfig.isEnableUpSignal)
                                                    GlobalMotion.Card_1.setOut((ushort)e_output_card1.上层物料NG, e_out_OnOff.off);
                                            }
                                            else
                                            {
                                                GlobalVar.Label_pros.Clear();
                                                if (GlobalVar.userConfig.isEnableUpSignal)
                                                    GlobalMotion.Card_1.setOut((ushort)e_output_card1.上层物料OK, e_out_OnOff.off);
                                            }
                                        }
                                       
                                        var nres = Step_ConveryUp(e_Step_ConveryUp.二段治具放行);
                                        if (nres != 1)
                                        {
                                            //MachineState(e_MachineStatus.异常急停, $"{e_ConveryLabel.ToString()}:二段治具放行");
                                            continue;
                                        }
                                         nres = Step_ConveryUp(e_Step_ConveryUp.二段治具下降);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_ConveryLabel.ToString()}:二段治具下降");
                                            continue;
                                        }
                                       
                                        Thread.Sleep(GlobalVar.userConfig.delayBlock2);
                                        e_ConveryLabel = e_Flow_ConveryUp.等待二段治具离开;
                                    }
                                    break;
                                case e_Flow_ConveryUp.等待二段治具离开:
                                    {
                                        if (!Input_CardEx2[(int)e_input_extCard2.上输送治具检测3])
                                        {
                                            var nres = Step_ConveryUp(e_Step_ConveryUp.二段治具阻挡);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_ConveryLabel.ToString()}:二段治具阻挡");
                                                continue;
                                            }
                                            isFirst = true;
                                            e_ConveryLabel = e_Flow_ConveryUp.上层下游交互;
                                            waitStop.Restart();
                                        }
                                    }
                                    break;

                                case e_Flow_ConveryUp.上层下游交互:
                                    if (GlobalVar.userConfig.isEnableUpSignal && !GlobalVar.IsRealsePro)
                                    {
                                        
                                        if (!Input_CardEx2[(int)e_input_extCard2.上输送治具检测4])
                                        {

                                            GlobalMotion.Card_1.setOut((ushort)e_output_card1.上层物料NG, e_out_OnOff.on);
                                            GlobalMotion.Card_1.setOut((ushort)e_output_card1.上层物料OK, e_out_OnOff.on);
                                            e_ConveryLabel = e_Flow_ConveryUp.等待二段治具到位;
                                        }
                                        else
                                        {
                                            if (!Input_Card1[(int)e_input_card1.上层向本机要料])
                                            {
                                                e_ConveryLabel = e_Flow_ConveryUp.送料中途下游停止要料;
                                                break;
                                            }
                                            if (waitStop.ElapsedMilliseconds > 5000)
                                            {
                                                displalyInfo.displayInfoMain("等待治具送出");
                                                waitStop.Restart();
                                            }
                                        }

                                    }
                                    else
                                    {
                                        e_ConveryLabel = e_Flow_ConveryUp.等待二段治具到位;
                                    }
                                    break;
                                case e_Flow_ConveryUp.送料中途下游停止要料:
                                    {
                                        if (GlobalVar.userConfig.isEnableUpSignal)
                                        {
                                            if (!Input_CardEx2[(int)e_input_extCard2.上输送治具检测4])
                                            {
                                                e_ConveryLabel = e_Flow_ConveryUp.上层下游交互;
                                                break;
                                            }
                                            if (Input_Card1[(int)e_input_card1.上层向本机要料])
                                            {
                                                e_ConveryLabel = e_Flow_ConveryUp.上层下游交互;
                                                break;
                                            }
                                            if (waitStop.ElapsedMilliseconds > 5000)
                                            {
                                                displalyInfo.displayInfoMain("等待下游恢复要料");
                                                waitStop.Restart();
                                            }
                                            
                                        }
                                        else
                                        {
                                            e_ConveryLabel = e_Flow_ConveryUp.上层下游交互;
                                        }
                                    }
                                    break;
                            }
                            if (logFlow != e_ConveryLabel.ToString())
                            {
                                logFlow = e_ConveryLabel.ToString();
                                displalyInfo.displayInfoMain(logFlow);
                            }
                        }
                        else
                            isFirst = true;
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_ConveryLabel" + ex.Message);
            }

        }
        public static bool IsAllToStop = false;
        /// <summary>
        public static bool IsProccessPro = false;
       
        /// <summary>
        /// 产品状态
        /// </summary>
        public static void Task_ProductState()
        {
            try
            {
                bool IsRun = false;
                while (!GlobalVar.isExit)
                {

                    Thread.Sleep(8);
                    if (!GlobalVar.isEstop)
                    {
                        if (GlobalVar.isAutoRun)
                        {
                            if (GlobalMotion.e_ConveryFront == e_Flow_ConveryUp.等待入料治具到位 &&
                              GlobalMotion.e_ConveryLaser == e_Flow_ConveryUp.等待一段治具到位 &&
                              GlobalMotion.e_ConveryLabel == e_Flow_ConveryUp.等待二段治具到位 &&
                              GlobalMotion.e_LabelingFlow == e_Flow_Labeling.等待开始检测产品信号 &&
                               GlobalMotion.e_Cut == e_Flow_Cut.等待有工装到达)
                            {
                                if (!Input_CardEx2[(int)e_input_extCard2.上输送治具检测1] && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测2]
                                    && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测3] && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测4]
                                    && !Input_CardEx1[(ushort)e_input_extCard1.上层顶升气缸到位1] && !Input_CardEx1[(ushort)e_input_extCard1.上层顶升气缸到位2])
                                {
                                    IsAllToStop = true;
                                }
                                else
                                    IsAllToStop = false;
                            }
                            else
                            {
                                IsAllToStop = false;
                            }
                        }
                        else
                            IsAllToStop = true;

                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_ProductState" + ex.Message);
            }
        }
        /// <summary>
        /// 实时监控卡状态
        /// </summary>
        public static void Task_CheckCard()
        {
            try
            {
                string logFlow = e_ConveryLaser.ToString();
                while (!GlobalVar.isExit)
                {
                    Thread.Sleep(300);
                    if (!GlobalVar.isEstop && GlobalVar.isAutoRun)
                    {
                        Thread.Sleep(200);
                        var res = GlobalMotion.Card_1.GetCardStatusCode();
                        if (res != 0)
                        {
                            MachineState(e_MachineStatus.异常急停, $"实时监控总线卡错误代号{res}  停机处理");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_ConveryDown" + ex.Message);
            }
        }
        /// <summary>
        /// 检测是否可以结束作业操作开始
        /// </summary>
        public static void Task_CheckStop()
        {
            try
            {

                while (!GlobalVar.isExit)
                {
                    Thread.Sleep(300);
                    if (!GlobalVar.isEstop && GlobalVar.isAutoRun && !GlobalVar.isPause)
                    {
                        if (GlobalVar.IsEndWork&&!GlobalVar.IsStart_EndWork)
                        {
                            Thread.Sleep(3000);
                            if (e_ConveryFront == e_Flow_ConveryUp.等待入料治具到位 && e_ConveryLaser == e_Flow_ConveryUp.等待一段治具到位 && e_ConveryLabel == e_Flow_ConveryUp.等待二段治具到位)
                            {
                                if (GlobalVar.curWorkMode == e_WorkMode.生产模式)
                                {
                                    if (e_LabelingFlow == e_Flow_Labeling.等待开始检测产品信号 && e_Cut == e_Flow_Cut.等待有工装到达)//撕膜流程+贴标流程无料
                                    {
                                        bool isnoHave = !Input_CardEx2[(int)e_input_extCard2.上输送治具检测1] && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] &&
                                              !Input_CardEx2[(int)e_input_extCard2.上输送治具检测3] && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测4];
                                        if (isnoHave)
                                        {
                                            GlobalVar.IsStart_EndWork = true;
                                            
                                        }
                                        else
                                        {
                                            displalyInfo.displayInfoMain("上层输送有治具  等待载具清空再清料");
                                            continue;
                                        }
                                    }
                                }
                                else
                                {
                                    bool isnoHave = !Input_CardEx2[(int)e_input_extCard2.上输送治具检测1] && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] &&
                                              !Input_CardEx2[(int)e_input_extCard2.上输送治具检测3] && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测4];
                                    if (isnoHave)
                                    {
                                       
                                        GlobalVar.isAllHome = false;
                                        GlobalVar.isAutoRun = false;
                                        GlobalVar.IsStart_EndWork = false;

                                        GlobalVar.IsEndWork = false;
                                        GlobalVar.IsStatusAuto = false;
                                    }
                                }
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_ConveryDown" + ex.Message);
            }
        }
        /// <summary>
        /// 结束作业
        /// </summary>
        public static void Task_EndWork()
        {
            try
            {

                while (!GlobalVar.isExit)
                {
                    Thread.Sleep(30);
                    if (!GlobalVar.isEstop && GlobalVar.isAutoRun && !GlobalVar.isPause && GlobalVar.IsEndWork)
                    {
                        if (GlobalVar.IsStart_EndWork)
                        {
                            //先气缸抬起  Z轴移动到1
                            var res = GlobalMotion.Step_Labeling(e_Step_Label.取标气缸抬起, e_platePro.双平台有);
                            if (res != 1)
                            {
                                MachineState(e_MachineStatus.异常急停, "结束作业:取标气缸抬起");
                                continue;
                            }
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, 1, 1, true);//Z轴抬起
                            if (!bres)
                            {
                                MachineState(e_MachineStatus.异常急停, "结束作业: Z轴抬起");
                                continue;
                            }
                            res = MachineState(e_MachineStatus.暂停控制);
                            if (res != 1)
                            {
                                continue;
                            }
                            //平台1X移至安全位  Y移至拍照位X
                            #region X移动到可旋转位
                            List<SigleAxis> posList = new List<SigleAxis>();
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标X1下,
                                pos = GlobalVar.motionConfig.scanSafeX1,
                                velrate = 1
                            });
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标X2上,
                                pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].X,
                                velrate = 1
                            });
                            bres = GlobalMotion.toPostionMutil(posList);
                            if (!bres)
                            {
                                MachineState(e_MachineStatus.异常急停, "结束作业:X移动到可旋转位失败");
                                continue;
                            }
                            res = MachineState(e_MachineStatus.暂停控制);
                            if (res != 1)
                            {
                                continue;
                            }
                            #endregion
                            //移动到拍照位Y  R1  R2
                            #region Y轴到达拍照位Y
                            bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Y轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].Y, 1, true);//Z轴抬起
                            if (!bres)
                            {
                                MachineState(e_MachineStatus.异常急停, "结束作业: Y轴到达拍照位Y失败");
                                continue;
                            }
                            res = MachineState(e_MachineStatus.暂停控制);
                            if (res != 1)
                            {
                                continue;
                            }
                            #endregion
                            #region R移动到可旋转到0度
                            List<SigleAxis> posList_R = new List<SigleAxis>();
                            posList_R.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标R1下,
                                pos = 0,
                                velrate = 1
                            });
                            posList_R.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标R2上,
                                pos = 0,
                                velrate = 1
                            });
                            bres = GlobalMotion.toPostionMutil(posList_R);
                            if (!bres)
                            {
                                MachineState(e_MachineStatus.异常急停, "结束作业:R移动到可旋转到0度失败");
                                continue;
                            }
                            res = MachineState(e_MachineStatus.暂停控制);
                            if (res != 1)
                            {
                                continue;
                            }
                            #endregion
                            //检查是否有膜在靶面上      
                            res = Step_Labeling(e_Step_Label.检测吸标靶面真空, e_platePro.双平台有);
                            if (res != -1)//靶面上有料
                            {
                                #region     拍照NG处理
                                var nres = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照NG位上方, e_platePro.双平台有);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, "结束作业:移至拍照NG位上方");
                                    continue;
                                }
                                nres = Step_Labeling(e_Step_Label.吸标NG旋转到取标位, e_platePro.双平台有);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业:吸标NG旋转到取标位");
                                    continue;
                                }
                                nres = Step_Labeling(e_Step_Label.取标气缸下压, e_platePro.双平台有);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业:取标气缸下压");
                                    continue;
                                }
                                nres = Step_Labeling(e_Step_Label.拍照NG位向下移动, e_platePro.双平台有);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业 拍照NG位向下移动");
                                    continue;
                                }
                                nres = Step_Labeling(e_Step_Label.放标签破真空, e_platePro.双平台有);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业 放标签破真空");
                                    continue;
                                }
                                Thread.Sleep(GlobalVar.userConfig.airTime);
                                nres = Step_Labeling(e_Step_Label.移至拍照NG位上方, e_platePro.双平台有);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业 移至拍照NG位上方");
                                    continue;
                                }
                                nres = Step_Labeling(e_Step_Label.取标气缸抬起, e_platePro.双平台有);
                                if (nres != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业 取标气缸抬起");
                                    continue;
                                }
                                #endregion
                            }
                            if (Input_CardEx1[(int)e_input_extCard1.飞达1平台有料] || Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])//其中一个平台有料时
                            {
                                res = MutilStep(e_Mutil_step.移至取标位取标, e_platePro.双平台有);
                                res = MachineState(e_MachineStatus.暂停控制);
                                if (res != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业:移至取标位取标异常");
                                    continue;
                                }
                                #region  拍照NG处理
                                var nresNG = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照NG位上方, e_platePro.双平台有);
                                if (nresNG != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, "结束作业:移至拍照NG位上方");
                                    continue;
                                }
                                nresNG = Step_Labeling(e_Step_Label.吸标NG旋转到取标位, e_platePro.双平台有);
                                if (nresNG != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业:吸标NG旋转到取标位");
                                    continue;
                                }
                                nresNG = Step_Labeling(e_Step_Label.取标气缸下压, e_platePro.双平台有);
                                if (nresNG != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业:取标气缸下压");
                                    continue;
                                }
                                nresNG = Step_Labeling(e_Step_Label.拍照NG位向下移动, e_platePro.双平台有);
                                if (nresNG != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业 拍照NG位向下移动");
                                    continue;
                                }
                                nresNG = Step_Labeling(e_Step_Label.放标签破真空, e_platePro.双平台有);
                                if (nresNG != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业 放标签破真空");
                                    continue;
                                }
                                Thread.Sleep(GlobalVar.userConfig.airTime);
                                nresNG = Step_Labeling(e_Step_Label.移至拍照NG位上方, e_platePro.双平台有);
                                if (nresNG != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业 移至拍照NG位上方");
                                    continue;
                                }
                                nresNG = Step_Labeling(e_Step_Label.取标气缸抬起, e_platePro.双平台有);
                                if (nresNG != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业 取标气缸抬起");
                                    continue;
                                }
                                nresNG = Step_Labeling(e_Step_Label.吸标NG旋转到放标位, e_platePro.双平台有);
                                if (nresNG != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业 吸标NG旋转到放标位");
                                    continue;
                                }
                                nresNG = Step_Labeling(e_Step_Label.移至取标位上方, e_platePro.双平台有);
                                if (nresNG != 1)
                                {
                                    MachineState(e_MachineStatus.异常急停, $"结束作业 移至取标位上方");
                                    continue;
                                }
                                #endregion
                            }
                            GlobalVar.isAllHome = false;
                            GlobalVar.isAutoRun = false;
                            GlobalVar.IsStart_EndWork = false;
                  
                            GlobalVar.IsEndWork = false;
                            GlobalVar.IsStatusAuto = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_ConveryDown" + ex.Message);
            }
        }
        /// <summary>
        /// 开机第几次贴标
        /// </summary>
        public static int nLabelTimes = 0;
       
        /// <summary>
        /// Ng 流水线抛料
        /// </summary>
        /// <param name="NGTempPlate"></param>
        /// <returns></returns>
        public static int MutilStep_NGPut(e_platePro NGTempPlate)
        {
            try
            {
                var nres = Step_Labeling(e_Step_Label.移至NG取工装时贴标Z轴安全位, NGTempPlate);
                if (nres != 1)
                {
                    MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:移至NG取工装时贴标Z轴安全位");
                    return nres;
                }
                nres = Step_Labeling(e_Step_Label.移至NG取工装位上, NGTempPlate);
                if (nres != 1)
                {
                    MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:移至NG取工装位上");
                    return nres;
                }
                nres = Step_Labeling(e_Step_Label.NG取工装位下降, NGTempPlate);
                if (nres != 1)
                {
                    MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG取工装位下降");
                    return nres;
                }
                nres = Step_Labeling(e_Step_Label.NG取工装吸真空, NGTempPlate);
                if (nres != 1)
                {
                    MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG吸工装吸真空");
                    return nres;
                }
                nres = Step_Labeling(e_Step_Label.NG取工装位上升, NGTempPlate);
                if (nres != 1)
                {
                    MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG取工装位上升");
                    return nres;
                }
                if (NGTempPlate == e_platePro.双平台有)
                {
                    if (!Input_CardEx2[(int)e_input_extCard2.上输送产品检测3] || !Input_CardEx2[(int)e_input_extCard2.上输送产品检测4])
                    {
                        if (GlobalMotion.TipInfo("双平台有 NG取双产品时没成功取产品,是否继续？是：继续下一步  否：急停处理") !=1)
                        {
                            MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG取工装失败");
                            return -1;
                        }
                    }
                }
                else if (NGTempPlate == e_platePro.平台1)
                {
                    if (!Input_CardEx2[(int)e_input_extCard2.上输送产品检测3])
                    {
                        //GlobalVar.isPause = true;
                        if ( GlobalMotion.TipInfo("平台1 NG取产品1时没成功取产品,是否继续？是：继续下一步  否：急停处理") !=1)
                        {
                            MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG取产品失败");
                            return -1;
                        }
                        GlobalVar.isPause = false;
                    }
                }
                else if (NGTempPlate == e_platePro.平台2)
                {
                    if (!Input_CardEx2[(int)e_input_extCard2.上输送产品检测4])
                    {
                        //GlobalVar.isPause = true;
                        if (GlobalMotion.TipInfo("平台2 NG取产品2时没成功取产品,是否继续？是：继续下一步  否：急停处理") !=1)
                        {
                            MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG取产品失败");
                            return -1;
                        }
                        GlobalVar.isPause = false;
                    }
                }
                nres = Step_Labeling(e_Step_Label.移至NG放工装位上, NGTempPlate);
                if (nres != 1)
                {
                    MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:移至NG放工装位上");
                    return nres;
                }
                if (NGTempPlate == e_platePro.双平台有)
                {
                    if (!Input_CardEx2[(int)e_input_extCard2.NG输送产品检测1] || !Input_CardEx2[(int)e_input_extCard2.NG输送产品检测2])
                    {
                        if (!CMachine.Instance.IsTestModel)
                        {
                            if (GlobalMotion.TipInfo("双平台有 NG输送上已有两产品,是否继续？是：继续下一步  否：急停处理") !=1)
                            {
                                MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG放产品失败");
                                return -1;
                            }

                        }
                    }
                }
                else if (NGTempPlate == e_platePro.平台1)
                {
                    if (!Input_CardEx2[(int)e_input_extCard2.NG输送产品检测1])
                    {
                        if (!CMachine.Instance.IsTestModel)
                        {
                            //GlobalVar.isPause = true;
                            if (GlobalMotion.TipInfo("平台1 NG输送上产品1位置上已有产品,是否继续？是：继续下一步  否：急停处理") !=1)
                            {
                                MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG放产品失败");
                                return -1;
                            }
                            GlobalVar.isPause = false;
                        }
                       
                    }
                }
                else if (NGTempPlate == e_platePro.平台2)
                {
                    if (!Input_CardEx2[(int)e_input_extCard2.NG输送产品检测2])
                    {
                        if (!CMachine.Instance.IsTestModel)
                        {
                            //GlobalVar.isPause = true;
                            if (GlobalMotion.TipInfo("平台2 NG输送上产品2位置上已有产品,是否继续？是：继续下一步  否：急停处理") !=1)
                            {
                                MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG放产品失败");
                                return -1;
                            }
                            GlobalVar.isPause = false;
                        }
                    }
                }
                nres = Step_Labeling(e_Step_Label.NG放工装位下降, NGTempPlate);
                if (nres != 1)
                {
                    MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG放工装位下降");
                    return nres;
                }
                nres = Step_Labeling(e_Step_Label.NG放工装破真空, NGTempPlate);
                if (nres != 1)
                {
                    MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG放工装破真空");
                    return nres;
                }
                nres = Step_Labeling(e_Step_Label.NG放工装位上升, NGTempPlate);
                if (nres != 1)
                {
                    MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG放工装位上升");
                    return nres;
                }

                if (NGTempPlate == e_platePro.双平台有)
                {
                    if (Input_CardEx2[(int)e_input_extCard2.NG输送产品检测1] || Input_CardEx2[(int)e_input_extCard2.NG输送产品检测2])
                    {
                        if (CMachine.Instance.IsTestModel)
                        {
                            return 1;
                        }
                        //GlobalVar.isPause = true;
                        if (GlobalMotion.TipInfo("双平台有 两产品放NG输送上检测不到,是否继续？是：继续下一步  否：急停处理") !=1)
                        {
                            MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:放NG输送产品失败");
                            return -1;
                        }
                        GlobalVar.isPause = false;
                    }

                    GlobalVar.IsStartConveryNG = true;
                }
                else if (NGTempPlate == e_platePro.平台1)
                {
                    if (Input_CardEx2[(int)e_input_extCard2.NG输送产品检测1])
                    {
                        if (!CMachine.Instance.IsTestModel)
                        {
                            //GlobalVar.isPause = true;
                            if (GlobalMotion.TipInfo("平台1 产品1放NG输送上检测不到,是否继续？是：继续下一步  否：急停处理") !=1)
                            {
                                MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:放NG输送产品失败");
                                return -1;
                            }
                            GlobalVar.isPause = false;
                        }
                        
                    }
                    GlobalVar.IsStartConveryNG = true;

                }
                else if (NGTempPlate == e_platePro.平台2)
                {
                    if (Input_CardEx2[(int)e_input_extCard2.NG输送产品检测2])
                    {
                        if (!CMachine.Instance.IsTestModel)
                        {
                            //GlobalVar.isPause = true;
                            if ( GlobalMotion.TipInfo("产品2 放NG输送上检测不到,是否继续？是：继续下一步  否：急停处理")!=1)
                            {
                                MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:放NG输送产品失败");
                                return -1;
                            }
                            GlobalVar.isPause = false;
                        }
                        
                    }

                    GlobalVar.IsStartConveryNG = true;
                }
                //物料放下，移动NG流水线
                Task.Run(()=>
                {
                    try
                    {
                        if (!Input_CardEx2[(int)e_input_extCard2.NG输送产品检测3])
                        {
                            GlobalMotion.TipInfo("NG输送产品检测3上已满料,请检查！");
                        }
                        else
                        {
                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.NG输送].ClearPos();
                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.NG输送].PointMove((double)GlobalVar.userConfig.NG_distance, false);
                        }
                    }
                    catch (Exception)
                    {
                    }
                });
                return 1;
            }
            catch (Exception ex)
            {
                displalyInfo.displayErrorMain("移除产品到NG输送上失败");
                return -1;
            }
        }

        /// <summary>
        /// 流程-NG输送 NG 抛料
        /// </summary>
        public static void Task_NGConvery()
        {
            //try
            //{
            //    while (!GlobalVar.isExit)
            //    {
            //        Thread.Sleep(8);
            //        if (!GlobalVar.isEstop)
            //        {
            //            if (GlobalVar.isAutoRun)
            //            {
            //                if (!Input_CardEx2[(int)e_input_extCard2.NG输送产品检测1] &&
            //                    !Input_CardEx2[(int)e_input_extCard2.NG输送产品检测2] &&
            //                    !Input_CardEx2[(int)e_input_extCard2.NG输送产品检测3] && !GlobalVar.isPause && GlobalVar.isAutoRun)
            //                {

            //                    GlobalMotion.TipInfo("NG输送上已满料");
            //                }
            //                if (GlobalVar.IsStartConveryNG)
            //                {
            //                    GlobalVar.IsStartConveryNG = false;
            //                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.NG输送].ClearPos();
            //                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.NG输送].PointMove((double)GlobalVar.userConfig.NG_distance, false);
            //                }
            //            }
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    displalyInfo.displayInfoMain("Task_NGConvery" + ex.Message);
            //}
        }

        static Stopwatch sw_stop = new Stopwatch();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e_status"></param>
        /// <returns>1表示可以继续运行</returns>
        public static int MachineState(e_MachineStatus e_status, string error = "")
        {
            sw_stop.Restart();
            switch (e_status)
            {
                case e_MachineStatus.无控制:
                    break;
                case e_MachineStatus.暂停控制:
                    while (GlobalVar.isPause)
                    {
                        if (sw_stop.ElapsedMilliseconds > 10000)
                        {
                            displalyInfo.displayInfoMain("机器暂停中");
                            sw_stop.Restart();
                        }
                        Thread.Sleep(1);
                        Application.DoEvents();
                        if (GlobalVar.isEstop || GlobalVar.isExit || GlobalVar.isReseting)
                            break;
                    }
                    if (GlobalVar.isEstop || GlobalVar.isExit || GlobalVar.isReseting)
                        return -1;
                    break;
                case e_MachineStatus.异常急停:
                    var errorMsg = "异常:" + error;
                    displalyInfo.displayErrorMain(errorMsg);
                    GlobalVar.isPause = true;
                    GlobalVar.isAutoRun = false;
                    GlobalVar.isReseting = false;
                    GlobalVar.isAllHome = false;
                    GlobalVar.isEstop = true;
                    GlobalVar.IsStart_EndWork = false;
                    GlobalVar.IsEndWork = false;
                    if (GlobalVar.userConfig.isEnableUpSignal)
                    {
                        if (GlobalMotion.Output_Card1[(int)e_output_card1.上层向上游要料])
                            GlobalMotion.Card_1.setOut((ushort)e_output_card1.上层向上游要料, e_out_OnOff.on);
                    }
                    if (GlobalVar.userConfig.UploadInfo.IsUploadUrl)
                    {
                        if (!string.IsNullOrEmpty(GlobalVar.userConfig.UploadInfo.url_AlarmUpload))
                        {
                            Task.Run(() => UploadInterface.upload_AlarmUpload(errorMsg));
                        }
                    }
                    try
                    {
                        var proids = "";
                        if (GlobalVar.Laser_pros!=null&&GlobalVar.Laser_pros.Count > 0)
                        {
                           var arr = GlobalVar.Laser_pros.Select(a => a.ProId).Distinct().ToArray();
                            proids += string.Join(" ", arr);
                        }
                        if (GlobalVar.Label_pros != null && GlobalVar.Label_pros.Count > 0)
                        {
                            var arr = GlobalVar.Label_pros.Select(a => a.ProId).Distinct().ToArray();
                            if(string.IsNullOrEmpty(proids))
                               proids += string.Join(" ", arr);
                            else
                              proids +="_"+ string.Join(" ", arr);
                        }
                        var sw_Alarm = new Stopwatch();
                        //sw_Alarm.Restart();
                        //while (curAlarm != null)
                        //{
                        //    Application.DoEvents();
                        //    if (sw_Alarm.ElapsedMilliseconds > 200)
                        //        break;
                        //    Thread.Sleep(10);
                        //}
                        var tempAlarm = new AlarmInfo() { AlarmMsg = errorMsg, startTime = DateTime.Now, ProIds = proids };
                        GlobalVar.sqlHelper.insert<AlarmInfo>(GlobalVar.userConfig.db_T_Alarm, tempAlarm);
                        GlobalMotion.addAlarmInfo?.Invoke(tempAlarm);
                       // var curAlarm = JsonConvert.DeserializeObject<AlarmInfo>(JsonConvert.SerializeObject(tempAlarm));
                        lock (lockAlarm)
                        {
                            lst_AlarmInfo.Add(tempAlarm);
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                    GlobalVar.IsMesEstop = false;
                    return -1;
                    break;
            }
            return 1;
        }
        private static List<AlarmInfo> lst_AlarmInfo = new List<AlarmInfo>();

        public static void Task_AlarmList()
        {
            string proids = "";
            AlarmInfo temp_Alarm = null;
            while (!GlobalVar.isExit)
            {
                Thread.Sleep(5);
                
              
                    lock (lockAlarm)
                    {
                        if (lst_AlarmInfo.Count > 0)
                        {
                            temp_Alarm = lst_AlarmInfo[0];
                            lst_AlarmInfo.RemoveAt(0);
                        }
                    }
                    if (temp_Alarm != null)
                    {
                    try
                    {
                        bool isExist = false;
                        for(int m=0;m<Application.OpenForms.Count;m++)
                        {
                            if(Application.OpenForms[m].Name== "PageAlarm")
                            {
                                isExist = true;
                                break;
                            }
                        }
                        if (!isExist)
                        {
                            pageAlarm = new PageAlarm(temp_Alarm);
                            Task.Run(()=> {
                                pageAlarm.ShowDialog();
                            });
                        }
                        else
                        {
                            pageAlarm.addAlarmInfo(temp_Alarm);
                        }
                        temp_Alarm = null;
                    }
                    catch (Exception ex)
                    {

                    }
                }
               
            }
        }
        public static PageAlarm pageAlarm = null;
        public static List<string> AlarmMsgs = new List<string>();
        public static int SaftRange = 12;
        private static DateTime alarm_startTime = DateTime.Now;
        private static object lockAlarm = new object();
        private static int GetSaftStatus(List<SigleAxisSafe> Axis)
        {
            try
            {

                if (Axis != null && Axis.Count > 0)
                {
                    bool isOK = true;
                    for (int m = 0; m < Axis.Count; m++)
                    {
                        var curPos = Card_1.AxisList[Axis[m].nAxis].m_AxisSts.CurrPosi;
                        if (Math.Abs(curPos - Axis[m].pos) < SaftRange)
                        {
                            isOK = true;
                        }
                        else
                        {
                            isOK = false;
                            break;
                        }
                    }
                    return isOK ? 1 : -1;
                }
                else
                {
                    return -1;
                }
            }
            catch
            {
                return -1;
            }
        }

        public static double GetCurrPosi(e_card1_axis Axis)
        {
            try
            {
                return Card_1.AxisList[(int)Axis].m_AxisSts.CurrPosi;
            }
            catch (Exception)
            {
                return 0;
            }
        }

        public static bool LogFlag = true;

        //是否旋转标志位
        public static bool[] LogFlag2 =new bool[2] {false ,false };

        /// <summary>
        /// 单步-贴膜
        /// </summary>
        /// <param name="e_Step"></param>
        /// <param name="e_Plate"></param>
        /// <returns></returns>
        public static int Step_Labeling(e_Step_Label e_Step, e_platePro e_Plate = e_platePro.双平台无, e_MachineStatus e_Staus = e_MachineStatus.暂停控制)
        {
            try
            {
                displalyInfo.displayInfoMain(e_Step.ToString());
                switch (e_Staus)
                {
                    case e_MachineStatus.手动界面:
                    case e_MachineStatus.无控制:
                        break;
                    case e_MachineStatus.暂停控制:
                        {
                            var nstop = MachineState(e_MachineStatus.暂停控制);
                            if (nstop != 1)
                                return -1;
                        }
                        break;
                }
                switch (e_Step)
                {
                    case e_Step_Label.取标位向下移动:
                        {
                            if (e_Staus == e_MachineStatus.手动界面)
                            {
                                //如果XYZR没在放标位上   操作无效

                                List<SigleAxisSafe> lst_pos = new List<SigleAxisSafe>();
                                switch (e_Plate)
                                {
                                    case e_platePro.平台1:
                                        {
                                            var AbsPos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位];
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X1下, pos = AbsPos.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标Y轴, pos = AbsPos.Y });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R1下, pos = AbsPos.R });
                                        }
                                        break;
                                    case e_platePro.平台2:
                                        {
                                            var AbsPos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.飞达取标位];
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X2上, pos = AbsPos.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标Y轴, pos = AbsPos.Y });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R2上, pos = AbsPos.R });
                                        }
                                        break;
                                    case e_platePro.双平台有:
                                        {
                                            var AbsPos1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位];
                                            var AbsPos2 = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.飞达取标位];
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X1下, pos = AbsPos1.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标Y轴, pos = AbsPos1.Y });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R1下, pos = AbsPos1.R });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X2上, pos = AbsPos2.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R2上, pos = AbsPos2.R });
                                        }
                                        break;
                                }

                                if (GetSaftStatus(lst_pos) != 1)
                                {
                                    string msg = $"当前贴标模组不在 飞达取标位 上  {e_Step.ToString()}失败 ";
                                    MessageBox.Show(msg);
                                    displalyInfo.displayErrorMain(msg);
                                    return -1;
                                }
                            }
                            var bres = false;
                            double zPos= 0;
                            if (CMachine.Instance.IsTestModel)
                            {
                                zPos = -10;
                            }
                            TimeWatch($"{e_Plate},取标向下移动", true, LogFlag);
                            if (e_Plate == e_platePro.平台1)
                            {
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位].Z + zPos, 5, true);
                            
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.飞达取标位].Z + zPos, 5, true);

                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位].Z + zPos, 5, true);

                            }
                            if (!bres)
                            {
                                TimeWatch($"{e_Plate},取标向下移动", false, LogFlag);
                                return -1;
                            }
                            else
                            {
                                TimeWatch($"{e_Plate},取标向下移动", false, LogFlag);
                                return 1;
                            }   
                        }
                        break;
                    case e_Step_Label.移至取标位上方:
                        {
                            //先 Z轴  再两R+两X+Y轴
                            if (e_Staus == e_MachineStatus.手动界面)
                            {
                                //如果Y方向要大于NG放料/拍照位时     平台1坐标X要在安全位以上
                                var y1 = Card_1.AxisList[(int)e_card1_axis.贴标Y轴].m_AxisSts.CurrPosi;
                                var NGy1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].Y;
                                var scany1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].Y;
                                if (y1 > NGy1 || y1 > scany1)
                                {
                                    var x1 = Card_1.AxisList[(int)e_card1_axis.贴标X1下].m_AxisSts.CurrPosi;
                                    if (x1 > (GlobalVar.motionConfig.scanSafeX1 + SaftRange))
                                    {
                                        string msg = $"当前贴标模组 平台1不在安全位 上  {e_Step.ToString()}失败 ";
                                        MessageBox.Show(msg);
                                        displalyInfo.displayErrorMain(msg);
                                        return -1;
                                    }
                                }
                            }
                            List<SigleAxis> posList = new List<SigleAxis>();
                            TimeWatch($"{e_Plate},移至取标位上方", true, LogFlag);
                            var nres11 = Step_Labeling(e_Step_Label.取标气缸抬起, e_Plate, e_MachineStatus.手动界面);
                            if (nres11 != 1)
                            {
                                MachineState(e_MachineStatus.异常急停, $"{e_Plate.ToString()}{e_LabelingFlow.ToString()}:取标气缸抬起");
                                return nres11;
                            }

                            if (e_Plate == e_platePro.双平台有)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位].ZHeight, 1, true);
                                if (!bres)
                                    return -1;
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, 0, 1, true);
                                if (!bres)
                                    return -1;
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R1下,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位].R,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R2上,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.飞达取标位].R,
                                    velrate = 1
                                });

                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标Y轴,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位].Y,
                                    velrate = 1.2f
                                });
                                bres = GlobalMotion.toPostionMutil(posList);
                                if (bres)
                                {
                                    posList = new List<SigleAxis>();
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.贴标X1下,
                                        pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位].X,
                                        velrate = 1.2f
                                    });
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.贴标X2上,
                                        pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.飞达取标位].X,
                                        velrate = 1.2f
                                    });
                                    bres = GlobalMotion.toPostionMutil(posList);
                                    if (!bres)
                                        return -1;
                                }
                                TimeWatch($"{e_Plate},移至取标位上方", false, LogFlag);
                                return bres ? 1 : -1;
                            }
                            else if (e_Plate == e_platePro.平台1)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位].ZHeight, 1, true);
                                if (!bres)
                                    return -1;
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, 0, 1, true);
                                if (!bres)
                                    return -1;
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R1下,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位].R,
                                    velrate = 1
                                });

                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标Y轴,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位].Y,
                                    velrate = 1.3f
                                });
                                bres = GlobalMotion.toPostionMutil(posList);
                                if (bres)
                                {
                                    bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标X1下, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.飞达取标位].X, 1.2f, true);
                                    if (!bres)
                                        return -1;
                                }
                                TimeWatch($"{e_Plate},移至取标位上方", false, LogFlag);
                                return bres ? 1 : -1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.飞达取标位].ZHeight, 1.2f, true);
                                if (!bres)
                                    return -1;
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, 0, 1, true);
                                if (!bres)
                                    return -1;
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R2上,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.飞达取标位].R,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标Y轴,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.飞达取标位].Y,
                                    velrate = 1.3f
                                });
                                bres = GlobalMotion.toPostionMutil(posList);
                                if (bres)
                                {
                                    bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标X2上, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.飞达取标位].X, 1.2f, true);
                                    if (!bres)
                                        return -1;
                                }
                                TimeWatch($"{e_Plate},移至取标位上方", false, LogFlag);
                                return bres ? 1 : -1;
                            }



                        }
                        break;
                    case e_Step_Label.取标气缸抬起:
                        {
                            var nres = -1;
                            TimeWatch($"{e_Plate},取标气缸抬起", true, LogFlag);
                            if (e_Plate == e_platePro.平台1)
                            {
                                nres = SetAir(e_output_extCard2.贴标升降气缸1, false, e_input_extCard2.贴标升降气缸原点1, true);
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                nres = SetAir(e_output_extCard2.贴标升降气缸2, false, e_input_extCard2.贴标升降气缸原点2, true);
                            }
                            else
                            {
                                nres = SetAir(e_output_extCard2.贴标升降气缸1, false, e_input_extCard2.贴标升降气缸原点1, true);
                                if (nres == 1)
                                    nres = SetAir(e_output_extCard2.贴标升降气缸2, false, e_input_extCard2.贴标升降气缸原点2, true);
                            }
                            TimeWatch($"{e_Plate},取标气缸抬起", false, LogFlag);
                            return nres;
                        }
                        break;
                    case e_Step_Label.取标气缸下压:
                        {
                            var nres = -1;
                            TimeWatch($"{e_Plate},取标气缸下压", true, LogFlag);
                            if (e_Plate == e_platePro.平台1)
                            {
                                nres = SetAir2(e_output_extCard2.贴标升降气缸1, true, e_input_extCard1.贴标气缸到位1, true);
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                nres = SetAir2(e_output_extCard2.贴标升降气缸2, true, e_input_extCard1.贴标气缸到位2, true);
                            }
                            else
                            {
                                nres = SetAir2(e_output_extCard2.贴标升降气缸1, true, e_input_extCard1.贴标气缸到位1, true);
                                if (nres == 1)
                                    nres = SetAir2(e_output_extCard2.贴标升降气缸2, true, e_input_extCard1.贴标气缸到位2, true);
                            }
                            TimeWatch($"{e_Plate},取标气缸下压", false, LogFlag);
                            return nres;
                        }
                        break;
                    case e_Step_Label.检测吸标靶面真空:
                        {
                            if (GlobalVar.IsOldTest || GlobalVar.userConfig.IsGetLabelOK)//强制检测OK
                            {
                                return 1;
                            }
                            if (e_Plate == e_platePro.平台1)
                            {

                                return Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1] == false ? (int)e_airResult.平台1已吸有料 : -1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {

                                return Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2] == false ? (int)e_airResult.平台2已吸有料 : -1;
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {

                                if (Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1] == false && Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2] == false)
                                {
                                    return (int)e_airResult.双平台已吸有料;
                                }
                                else if (Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1] == false)
                                    return (int)e_airResult.平台1已吸有料;
                                else if (Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2] == false)
                                    return (int)e_airResult.平台2已吸有料;
                                else
                                    return -1;
                            }

                        }
                        break;
                    case e_Step_Label.取标签吸真空:
                        {
                            var nres = -1;
                            TimeWatch($"{e_Plate},取标签吸真空", true, LogFlag);
                            if (GlobalVar.IsOldTest || GlobalVar.userConfig.IsGetLabelOK)
                            {
                                TimeWatch($"{e_Plate},取标签吸真空", false, LogFlag);
                                return 1;
                            }
                            if (e_Plate == e_platePro.平台1)
                            {
                                nres = SetAir(e_output_extCard2.吸标靶面吸气1, true, e_input_extCard2.吸标靶面真空报警1, false);
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                nres = SetAir(e_output_extCard2.吸标靶面吸气2, true, e_input_extCard2.吸标靶面真空报警2, false);
                            }
                            else
                            {

                                GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.吸标靶面吸气1, e_out_OnOff.off);
                                GlobalMotion.CardExt_2.setOut((ushort)e_output_extCard2.吸标靶面吸气2, e_out_OnOff.off);
                                Stopwatch sw = new Stopwatch();
                                sw.Restart();
                                while (true)
                                {
                                    if ((!Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1] && !Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2])||
                                        CMachine.Instance.IsTestModel)//信号取反
                                    {
                                        nres = (int)e_airResult.双平台已吸有料;
                                        break;
                                    }
                                    if (sw.ElapsedMilliseconds > SetAirTimeOut)
                                    {
                                        if (!Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1] && Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2])
                                            nres = (int)e_airResult.平台1已吸有料;//1可以  2不行
                                        else if (Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警1] && !Input_CardEx2[(int)e_input_extCard2.吸标靶面真空报警2])
                                            nres = (int)e_airResult.平台2已吸有料;//1可以  2不行
                                        else
                                            nres = (int)e_airResult.双平台吸无料;
                                        break;
                                    }
                                }
                            }
                            Thread.Sleep(GlobalVar.userConfig.airTime);
                            if (GlobalVar.IsOldTest || GlobalVar.userConfig.IsGetLabelOK)
                            {
                                TimeWatch($"{e_Plate},取标签吸真空", false, LogFlag);
                                return 1;
                            }
                            //if(nres ==-1)
                            //{
                            //    if (DialogResult.Yes == MessageBox.Show($"{e_Step.ToString()}异常，是否继续", "询问", MessageBoxButtons.YesNo))
                            //        nres = 1;
                            //}
                            TimeWatch($"{e_Plate},取标签吸真空", false, LogFlag);
                            return nres;
                        }
                        break;
                    case e_Step_Label.放标签破真空:
                        {
                            var nres = -1;
                            TimeWatch($"{e_Plate},放标签破真空", true, LogFlag);
                            if (e_Plate == e_platePro.平台1)
                            {
                                nres = SetAir(e_output_extCard2.吸标靶面吸气1, false, e_input_extCard2.吸标靶面真空报警1, true);
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                nres = SetAir(e_output_extCard2.吸标靶面吸气2, false, e_input_extCard2.吸标靶面真空报警2, true);
                            }
                            else
                            {
                                var res1 = SetAir(e_output_extCard2.吸标靶面吸气1, false, e_input_extCard2.吸标靶面真空报警1, true);

                                var res2 = SetAir(e_output_extCard2.吸标靶面吸气2, false, e_input_extCard2.吸标靶面真空报警2, true);
                                if (res1 == 1 && res2 == 1)
                                    nres = 1;

                            }

                            Thread.Sleep(GlobalVar.userConfig.airTime);
                            if (GlobalVar.IsOldTest)
                            {
                                TimeWatch($"{e_Plate},放标签破真空", false, LogFlag);
                                return 1;
                            }
                            if (nres == -1)
                            {
                                if(e_Staus==e_MachineStatus.无控制)
                                {
                                    if (DialogResult.Yes == MessageBox.Show($"{e_Step.ToString()}异常，是否继续", "询问", MessageBoxButtons.YesNo))
                                        nres = 1;
                                }
                              
                            }
                            TimeWatch($"{e_Plate},放标签破真空", false, LogFlag);
                            return nres;
                        }
                        break;
                    case e_Step_Label.拍照NG位向下移动:
                        {
                            if (e_Staus == e_MachineStatus.手动界面)
                            {
                                //如果XYZR没在放标位上   操作无效
                                List<SigleAxisSafe> lst_pos = new List<SigleAxisSafe>();
                                switch (e_Plate)
                                {
                                    case e_platePro.平台1:
                                        {
                                            var AbsPos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位];
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X1下, pos = AbsPos.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标Y轴, pos = AbsPos.Y });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R1下, pos = AbsPos.R });
                                        }
                                        break;
                                    case e_platePro.平台2:
                                        {
                                            var AbsPos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.NG放标位];
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X2上, pos = AbsPos.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标Y轴, pos = AbsPos.Y });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R2上, pos = AbsPos.R });
                                        }
                                        break;
                                    case e_platePro.双平台有:
                                        {
                                            var AbsPos1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位];
                                            var AbsPos2 = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.NG放标位];
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X1下, pos = AbsPos1.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标Y轴, pos = AbsPos1.Y });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R1下, pos = AbsPos1.R });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X2上, pos = AbsPos2.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R2上, pos = AbsPos2.R });
                                        }
                                        break;
                                }

                                if (GetSaftStatus(lst_pos) != 1)
                                {
                                    string msg = $"当前贴标模组不在 NG放标位 上  {e_Step.ToString()}失败 ";
                                    MessageBox.Show(msg);
                                    displalyInfo.displayErrorMain(msg);
                                    return -1;
                                }
                            }
                            var nres = -1;
                            if (e_Plate == e_platePro.平台1)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].Z, 1, true);
                                if (!bres)
                                    return -1;
                                else
                                    return 1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.NG放标位].Z, 1, true);
                                if (!bres)
                                    return -1;
                                else
                                    return 1;
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].Z, 1, true);
                                if (!bres)
                                    return -1;
                                else
                                    return 1;
                            }
                        }
                        break;
                    case e_Step_Label.移至拍照NG位上方:
                        {
                            if (e_Staus == e_MachineStatus.手动界面)
                            {
                                //如果Y方向要大于NG放料/拍照位时     平台1坐标X要在安全位以上
                                var y1 = Card_1.AxisList[(int)e_card1_axis.贴标Y轴].m_AxisSts.CurrPosi;
                                var NGy1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].Y;
                                var scany1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].Y;
                                if (y1 > NGy1 || y1 > scany1)
                                {
                                    var x1 = Card_1.AxisList[(int)e_card1_axis.贴标X1下].m_AxisSts.CurrPosi;
                                    if (x1 > (GlobalVar.motionConfig.scanSafeX1 + SaftRange))
                                    {
                                        string msg = $"当前贴标模组 平台1不在安全位 上  {e_Step.ToString()}失败 ";
                                        MessageBox.Show(msg);
                                        displalyInfo.displayErrorMain(msg);
                                        return -1;
                                    }
                                }
                            }
                            var nres = -1;
                            if (e_Plate == e_platePro.平台1)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].ZHeight, 1, true);
                                if (!bres)
                                    return -1;
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, 0, 1, true);
                                if (!bres)
                                    return -1;

                                List<SigleAxis> posList = new List<SigleAxis>();
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R1下,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].R,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标X1下,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].X,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标Y轴,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].Y,
                                    velrate = 1
                                });

                                bres = GlobalMotion.toPostionMutil(posList);
                                return bres ? 1 : -1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.NG放标位].ZHeight, 1, true);
                                if (!bres)
                                    return -1;
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, 0, 1, true);
                                if (!bres)
                                    return -1;
                                List<SigleAxis> posList = new List<SigleAxis>();
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R2上,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.NG放标位].R,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标X2上,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.NG放标位].X,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标Y轴,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.NG放标位].Y,
                                    velrate = 1
                                });
                                bres = GlobalMotion.toPostionMutil(posList);
                                return bres ? 1 : -1;
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].ZHeight, 1, true);
                                if (!bres)
                                    return -1;
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, 0, 1, true);
                                if (!bres)
                                    return -1;
                                List<SigleAxis> posList = new List<SigleAxis>();
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标X1下,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].X,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R1下,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].R,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R2上,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.NG放标位].R,
                                    velrate = 1
                                });

                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标X2上,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.NG放标位].X,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标Y轴,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.NG放标位].Y,
                                    velrate = 1
                                });
                                bres = GlobalMotion.toPostionMutil(posList);
                                return bres ? 1 : -1;
                            }
                        }
                        break;
                    case e_Step_Label.移至拍照位:
                        {
                            LogFlag2 = new bool[2] { false, false };
                            var nres = -1;
                            TimeWatch($"{e_Plate},移至拍照位", true, LogFlag);
                            if (e_Plate == e_platePro.平台1)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].Z, 1, true);
                                if (!bres)
                                {
                                    TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                    return -1;
                                }
                                    
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, 0, 1, true);
                                if (!bres)
                                {
                                    TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                    return -1;
                                }
                                //bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标R1下, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].R, 1, true);
                                //if (!bres)
                                //{
                                //    TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                //    return -1;
                                //}

                                List<SigleAxis> posList = new List<SigleAxis>();
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R1下,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].R,
                                    velrate = 1
                                });

                                //增加提前把右边的R轴旋转到位
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R2上,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].R,
                                    velrate = 1
                                });

                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标X1下,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].X,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标Y轴,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].Y,
                                    velrate = 1
                                });

                                bres = GlobalMotion.toPostionMutil(posList);
                                LogFlag2[0] = true;
                                TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                return bres ? 1 : -1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].Z, 1, true);
                                if (!bres)
                                {
                                    TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                    return -1;
                                }
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, 0, 1, true);
                                if (!bres)
                                {
                                    TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                    return -1;
                                }
                                //bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标R2上, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].R, 1, true);
                                //if (!bres)
                                //{
                                //    TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                //    return -1;
                                //}
                                List<SigleAxis> posList = new List<SigleAxis>();
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R2上,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].R,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标X2上,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].X,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标Y轴,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].Y,
                                    velrate = 1
                                });
                                bres = GlobalMotion.toPostionMutil(posList);
                                LogFlag2[1] = true;
                                TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                return bres ? 1 : -1;
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].Z, 1, true);
                                if (!bres)
                                {
                                    TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                    return -1;
                                }
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, 0, 1, true);
                                if (!bres)
                                {
                                    TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                    return -1;
                                }
                                //新增
                                //bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标R1下, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].R, 1, true);
                                //if (!bres)
                                //{
                                //    TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                //    return -1;
                                //}
                                //bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标R2上, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].R, 1, true);
                                //if (!bres)
                                //{
                                //    TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                //    return -1;
                                //}

                                List<SigleAxis> posList = new List<SigleAxis>();
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标Y轴,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].Y,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R1下,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].R,
                                    velrate = 1
                                });

                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标X1下,
                                    pos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].X,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R2上,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].R,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标X2上,
                                    pos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].X,
                                    velrate = 1
                                });

                                bres = GlobalMotion.toPostionMutil(posList);
                                TimeWatch($"{e_Plate},移至拍照位", false, LogFlag);
                                return bres ? 1 : -1;
                            }
                        }
                        break;
                    case e_Step_Label.移至OK位上方:
                        {
                            if (e_Staus == e_MachineStatus.手动界面)
                            {
                                //如果Y方向要大于NG放料/拍照位时     平台1坐标X要在安全位以上
                                var y1 = Card_1.AxisList[(int)e_card1_axis.贴标Y轴].m_AxisSts.CurrPosi;
                                var NGy1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].Y;
                                var scany1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].Y;
                                if (y1 > NGy1 || y1 > scany1)
                                {
                                    var x1 = Card_1.AxisList[(int)e_card1_axis.贴标X1下].m_AxisSts.CurrPosi;
                                    if (x1 > (GlobalVar.motionConfig.scanSafeX1 + SaftRange))
                                    {
                                        string msg = $"当前贴标模组 平台1不在安全位 上  {e_Step.ToString()}失败 ";
                                        MessageBox.Show(msg);
                                        displalyInfo.displayErrorMain(msg);
                                        return -1;
                                    }
                                }
                            }
                            var nres = -1;
                            TimeWatch($"{e_Plate},移至OK位上方", true, LogFlag);
                            if (e_Plate == e_platePro.平台1)
                            {

                                List<SigleAxis> posList = new List<SigleAxis>();
                                var angel = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.OK放标位].R;
                                var angel2 = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.OK放标位].R;
                                var x = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.OK放标位].X;
                                var y = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.OK放标位].Y;

                                //if (visionProc.ResultPlate1 != null && !GlobalVar.IsOldTest)
                                //{
                                //    if (GlobalVar.userConfig.isEnableVisionsyr)
                                //    {
                                //        x += (visionProc.ResultPlate1.X);
                                //        y += (visionProc.ResultPlate1.Y);
                                //        angel += visionProc.ResultPlate1.Angle;
                                //        displalyInfo.displayInfoMain($"平台1补偿量 x:{visionProc.ResultPlate1.X }  y:{visionProc.ResultPlate1.Y } " +
                                //            $" R:{visionProc.ResultPlate1.Angle }");
                                //    }
                                //    if (GlobalVar.userConfig.IsPosAfterLabel && visionProc.LabelPostion1 != null && GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.已拍照OK)
                                //    {

                                //        if (visionProc.LabelPostion1.Angle >= -VarXYR && visionProc.LabelPostion1.Angle <= VarXYR
                                //            && visionProc.LabelPostion1.X >= -VarXYR && visionProc.LabelPostion1.X <= VarXYR
                                //            && visionProc.LabelPostion1.Y >= -VarXYR && visionProc.LabelPostion1.Y <= VarXYR)
                                //        {
                                //            displalyInfo.displayInfoMain($"加上治具补偿前 x:{x }  y:{y }  R:{angel }");
                                //            x += (visionProc.LabelPostion1.X);
                                //            y -= (visionProc.LabelPostion1.Y);
                                //            angel += (visionProc.LabelPostion1.Angle);
                                //            displalyInfo.displayInfoMain($"平台2补偿量 x:{visionProc.ResultPlate1.X }  y:{visionProc.ResultPlate1.Y } " +
                                //            $" R:{visionProc.ResultPlate1.Angle }");
                                //        }

                                //    }
                                //}
                                //displalyInfo.displayInfoMain($"当前OK位 x:{x }  y:{y }  R:{angel }");

                                angel = angel + VisionUP_LeftResultPlate.Angle + GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.视觉补偿].R;
                                x = x + VisionUP_LeftResultPlate.X + GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.视觉补偿].X;
                                y = y + VisionUP_LeftResultPlate.Y + GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.视觉补偿].Y;

                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R2上,
                                    pos = angel2,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R1下,
                                    pos = angel,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标X1下,
                                    pos = x,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标Y轴,
                                    pos = y,
                                    velrate = 1.3f
                                });

                                var bres = GlobalMotion.toPostionMutil(posList);
                                if (!bres)
                                {
                                    TimeWatch($"{e_Plate},移至OK位上方", false, LogFlag);
                                    return -1;
                                }
                                 bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.OK放标位].ZHeight, 1, true);
                                TimeWatch($"{e_Plate},移至OK位上方", false, LogFlag);
                                return bres ? 1 : -1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {

                                List<SigleAxis> posList = new List<SigleAxis>();
                                var angel = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.OK放标位].R;
                                var angel1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.OK放标位].R;
                                var x = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.OK放标位].X;
                                var y = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.OK放标位].Y;

                                //if (visionProc.ResultPlate2 != null && !GlobalVar.IsOldTest)
                                //{
                                //    if (GlobalVar.userConfig.isEnableVisionsyr)
                                //    {
                                //        x -= visionProc.ResultPlate2.X;
                                //        y -= visionProc.ResultPlate2.Y;
                                //        angel += visionProc.ResultPlate2.Angle;
                                //    }
                                //    if (GlobalVar.userConfig.IsPosAfterLabel && visionProc.LabelPostion2 != null && GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.已拍照OK)
                                //    {

                                //        if (visionProc.LabelPostion2.Angle >= -VarXYR && visionProc.LabelPostion2.Angle <= VarXYR
                                //            && visionProc.LabelPostion2.X >= -VarXYR && visionProc.LabelPostion2.X <= VarXYR
                                //            && visionProc.LabelPostion2.Y >= -VarXYR && visionProc.LabelPostion2.Y <= VarXYR)
                                //        {
                                //            displalyInfo.displayInfoMain($"加上治具补偿前 x:{x }  y:{y }  R:{angel }");
                                //            x -= (visionProc.LabelPostion2.X);
                                //            y -= (visionProc.LabelPostion2.Y);
                                //            //x += (visionProc.LabelPostion2.Y);
                                //            //y -= (visionProc.LabelPostion2.X);
                                //            angel += (visionProc.LabelPostion2.Angle);
                                //        }
                                //    }
                                //}
                                //displalyInfo.displayInfoMain($"当前OK位 x:{x }  y:{y }  R:{angel }");
                                //var angel1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.OK放标位].R;

                                angel = angel + VisionUP_RightResultPlate.Angle + GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.视觉补偿].R;
                                x = x + VisionUP_RightResultPlate.X + GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.视觉补偿].X;
                                y = y + VisionUP_RightResultPlate.Y + GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.视觉补偿].Y;

                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R1下,
                                    pos = angel1,
                                    velrate = 1
                                });
                              
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标R2上,
                                    pos = angel,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标X2上,
                                    pos = x,
                                    velrate = 1
                                });
                                posList.Add(new SigleAxis()
                                {
                                    IsAbs = true,
                                    nAxis = (int)e_card1_axis.贴标Y轴,
                                    pos = y,
                                    velrate = 1.3f
                                });
                                var bres = GlobalMotion.toPostionMutil(posList);
                                if (!bres)
                                {
                                    TimeWatch($"{e_Plate},移至OK位上方", false, LogFlag);
                                    return -1;
                                }
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.OK放标位].ZHeight, 1, true);
                                TimeWatch($"{e_Plate},移至OK位上方", false, LogFlag);
                                return bres ? 1 : -1;
                            }
                        }
                        break;
                    case e_Step_Label.OK位向下移动:
                        {
                            if (e_Staus == e_MachineStatus.手动界面)
                            {
                                //如果XYZR没在放标位上   操作无效

                                List<SigleAxisSafe> lst_pos = new List<SigleAxisSafe>();
                                switch (e_Plate)
                                {
                                    case e_platePro.平台1:
                                        {
                                            var AbsPos = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.OK放标位];
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X1下, pos = AbsPos.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标Y轴, pos = AbsPos.Y });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R1下, pos = AbsPos.R });
                                        }
                                        break;
                                    case e_platePro.平台2:
                                        {
                                            var AbsPos = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.OK放标位];
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X2上, pos = AbsPos.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标Y轴, pos = AbsPos.Y });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R2上, pos = AbsPos.R });
                                        }
                                        break;
                                    case e_platePro.双平台有:
                                        {
                                            var AbsPos1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.OK放标位];
                                            var AbsPos2 = GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.OK放标位];
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X1下, pos = AbsPos1.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标Y轴, pos = AbsPos1.Y });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R1下, pos = AbsPos1.R });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标X2上, pos = AbsPos2.X });
                                            lst_pos.Add(new SigleAxisSafe() { nAxis = (int)e_card1_axis.贴标R2上, pos = AbsPos2.R });
                                        }
                                        break;
                                }

                                if (GetSaftStatus(lst_pos) != 1)
                                {
                                    string msg = $"当前贴标模组不在 OK放标位 上  {e_Step.ToString()}失败 ";
                                    MessageBox.Show(msg);
                                    displalyInfo.displayErrorMain(msg);
                                    return -1;
                                }
                            }
                            var nres = -1;
                            TimeWatch($"{e_Plate},OK位向下移动", true, LogFlag);
                            if (e_Plate == e_platePro.平台1)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.OK放标位].Z, 1, true);
                                TimeWatch($"{e_Plate},OK位向下移动", false, LogFlag);
                                return bres ? 1 : -1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.OK放标位].Z, 1, true);
                                TimeWatch($"{e_Plate},OK位向下移动", false, LogFlag);
                                return bres ? 1 : -1;

                            }
                        }
                        break;
                    case e_Step_Label.移至NG取工装时贴标Z轴安全位:
                        {
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.NGlabelZ, 1, true);
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Label.移至拍照安全位X:
                        {
                            var nres = -1;
                            TimeWatch($"{e_Plate},移至拍照安全位X", true, LogFlag);
                            if (e_Plate == e_platePro.平台1)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标X1下, GlobalVar.motionConfig.scanSafeX1, 1.2f, true);
                                TimeWatch($"{e_Plate},移至拍照安全位X", false, LogFlag);
                                return bres ? 1 : -1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标X2上, GlobalVar.motionConfig.scanSafeX2, 1.2f, true);
                                TimeWatch($"{e_Plate},移至拍照安全位X", false, LogFlag);
                                return bres ? 1 : -1;

                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标X1下, GlobalVar.motionConfig.scanSafeX1, 1.2f, true);
                                bres &= GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标X2上, GlobalVar.motionConfig.scanSafeX2, 1.2f, true);
                                TimeWatch($"{e_Plate},移至拍照安全位X", false, LogFlag);
                                return bres ? 1 : -1;

                            }
                        }
                        break;
                    case e_Step_Label.拍照:
                        {
                            var nres = -1;
                            TimeWatch($"{e_Plate},拍照", true, LogFlag);
                            if (GlobalVar.userConfig.delayCamera > 0)
                                Thread.Sleep(GlobalVar.userConfig.delayCamera);
                            Application.DoEvents();
                            if (e_Plate == e_platePro.平台1)
                            {
                                GlobalVar.IsProccessed1 = false;
                                GlobalVar.e_Camera_Pos1 = e_Camera_Pos.未拍照;
                                if (!GlobalVar.userConfig.isPosOk && !GlobalVar.IsOldTest)
                                {
                                    VisionDown_LeftResultPlate = new xPostion();
                                    if (Station_DownCameraTrigger(e_Plate, out VisionDown_LeftResultPlate.X , out VisionDown_LeftResultPlate.Y, out VisionDown_LeftResultPlate.Angle, out string meg) == 1)
                                    {
                                        GlobalVar.e_Camera_Pos1 = e_Camera_Pos.已拍照OK;
                                        GlobalVar.IsProccessed1 = true;
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Pos1 = e_Camera_Pos.已拍照NG;
                                        GlobalVar.IsProccessed1 = false;
                                    }
                                }
                                else
                                {
                                    GlobalVar.e_Camera_Pos1 = e_Camera_Pos.已拍照OK;
                                    GlobalVar.IsProccessed1 = true;
                                }
                                // GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.定位相机触发, e_out_OnOff.on);
                                TimeWatch($"{e_Plate},拍照", false, LogFlag);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                GlobalVar.IsProccessed2 = false;
                                GlobalVar.e_Camera_Pos2 = e_Camera_Pos.未拍照;
                                if (!GlobalVar.userConfig.isPosOk && !GlobalVar.IsOldTest)
                                {
                                    VisionDown_RightResultPlate = new xPostion();
                                    if (Station_DownCameraTrigger(e_Plate, out VisionDown_RightResultPlate.X, out VisionDown_RightResultPlate.Y, out VisionDown_RightResultPlate.Angle, out string meg) == 1)
                                    {
                                        GlobalVar.e_Camera_Pos2 = e_Camera_Pos.已拍照OK;
                                        GlobalVar.IsProccessed2 = true;
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Pos2 = e_Camera_Pos.已拍照NG;
                                        GlobalVar.IsProccessed2 = false;
                                    }
                                }
                                else
                                {
                                    GlobalVar.e_Camera_Pos2 = e_Camera_Pos.已拍照OK;
                                    GlobalVar.IsProccessed2 = true;
                                }
                                //GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.定位相机触发, e_out_OnOff.on);
                                TimeWatch($"{e_Plate},拍照", false, LogFlag);
                                return 1;
                            }
                           
                        }
                        break;
                    case e_Step_Label.移至拍照检测位:
                        {
                            if (e_Staus == e_MachineStatus.手动界面)
                            {
                                //如果Y方向要大于NG放料/拍照位时     平台1坐标X要在安全位以上
                                var y1 = Card_1.AxisList[(int)e_card1_axis.贴标Y轴].m_AxisSts.CurrPosi;
                                var NGy1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].Y;
                                var scany1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].Y;
                                if (y1 > NGy1 || y1 > scany1)
                                {
                                    var x1 = Card_1.AxisList[(int)e_card1_axis.贴标X1下].m_AxisSts.CurrPosi;
                                    if (x1 > (GlobalVar.motionConfig.scanSafeX1 + SaftRange))
                                    {
                                        string msg = $"当前贴标模组 平台1不在安全位 上  {e_Step.ToString()}失败 ";
                                        MessageBox.Show(msg);
                                        displalyInfo.displayErrorMain(msg);
                                        return -1;
                                    }
                                }
                            }
                            var nres = -1;
                            //var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照检测位].Z, 1, true);
                            //if (!bres)
                            //    return -1;
                            TimeWatch($"{e_Plate},移至拍照检测位", true, LogFlag);


                            //旋转R电机后不需要再次旋转
                            if (LogFlag2[0]==false)
                            {
                                LogFlag2[0] = false;
                                var bres6 = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标R1下, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].R, 1, true);
                                if (!bres6)
                                {
                                    return -1;
                                }
                            }
                            if (LogFlag2[1] == false)
                            {
                                LogFlag2[1] = false;
                                var bres7 = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标R2上, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].R, 1, true);
                                if (!bres7)
                                {
                                    return -1;
                                }
                            }

                            List<SigleAxis> posList = new List<SigleAxis>();

                            //增加同步右工位X1轴与Y轴旋转到位
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标X2上,
                                pos = GlobalVar.motionConfig.scanSafeX2,
                                velrate = 1
                            });

                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标Y轴,
                                pos = GlobalVar.motionConfig.checkPosY,
                                velrate = 1
                            });
                            var bres = GlobalMotion.toPostionMutil(posList);
                            TimeWatch($"{e_Plate},移至拍照检测位", false, LogFlag);
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Label.移至拍照检测位上:
                        {
                            if (e_Staus == e_MachineStatus.手动界面)
                            {
                                //如果Y方向要大于NG放料/拍照位时     平台1坐标X要在安全位以上
                                var y1 = Card_1.AxisList[(int)e_card1_axis.贴标Y轴].m_AxisSts.CurrPosi;
                                var NGy1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].Y;
                                var scany1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].Y;
                                if (y1 > NGy1 || y1 > scany1)
                                {
                                    var x1 = Card_1.AxisList[(int)e_card1_axis.贴标X1下].m_AxisSts.CurrPosi;
                                    if (x1 > (GlobalVar.motionConfig.scanSafeX1 + SaftRange))
                                    {
                                        string msg = $"当前贴标模组 平台1不在安全位 上  {e_Step.ToString()}失败 ";
                                        MessageBox.Show(msg);
                                        displalyInfo.displayErrorMain(msg);
                                        return -1;
                                    }
                                }
                            }
                            var nres = -1;
                            //var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照检测位].Z, 1, true);
                            //if (!bres)
                            //    return -1; GlobalVar.motionConfig.NGlabelZ
                            TimeWatch($"{e_Plate},移至拍照检测位上", true, LogFlag);
                            var bres2 = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.NGlabelZ, 1, true);
                            if (!bres2)
                            {
                                TimeWatch($"{e_Plate},移至拍照检测位上", false, LogFlag);
                                return -1;
                            }


                            //nres = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台1, e_MachineStatus.无控制);
                            //if (nres != 1)
                            //{
                            //    TimeWatch($"{e_Plate},移至拍照检测位上", false, LogFlag);
                            //    return -1;
                            //}

                            List<SigleAxis> posList = new List<SigleAxis>();
                            //增加同步右工位X1轴与Y轴旋转到位
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标X1下,
                                pos = GlobalVar.motionConfig.scanSafeX1,
                                velrate = 1
                            });
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标X2上,
                                pos = GlobalVar.motionConfig.scanSafeX2,
                                velrate = 1
                            });

                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标Y轴,
                                pos = GlobalVar.motionConfig.Up_checkPosY,
                                velrate = 1
                            });
                            var bres = GlobalMotion.toPostionMutil(posList); 
                            TimeWatch($"{e_Plate},移至拍照检测位上", false, LogFlag);
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Label.移至拍照检测位下:
                        {
                            if (e_Staus == e_MachineStatus.手动界面)
                            {
                                //如果Y方向要大于NG放料/拍照位时     平台1坐标X要在安全位以上
                                var y1 = Card_1.AxisList[(int)e_card1_axis.贴标Y轴].m_AxisSts.CurrPosi;
                                var NGy1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].Y;
                                var scany1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].Y;
                                if (y1 > NGy1 || y1 > scany1)
                                {
                                    var x1 = Card_1.AxisList[(int)e_card1_axis.贴标X1下].m_AxisSts.CurrPosi;
                                    if (x1 > (GlobalVar.motionConfig.scanSafeX1 + SaftRange))
                                    {
                                        string msg = $"当前贴标模组 平台1不在安全位 上  {e_Step.ToString()}失败 ";
                                        MessageBox.Show(msg);
                                        displalyInfo.displayErrorMain(msg);
                                        return -1;
                                    }
                                }
                            }
                            var nres = -1; 
                            TimeWatch($"{e_Plate},移至拍照检测位下", true, LogFlag);
                            //Z轴移到安全位置
                            var bres2 = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.NGlabelZ, 1, true);
                            if (!bres2)
                            {
                                TimeWatch($"{e_Plate},移至拍照检测位下", false, LogFlag); 
                                return -1;
                            }
                                


                            //nres = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台1, e_MachineStatus.无控制);
                            //if (nres != 1)
                            //{
                            //    TimeWatch($"{e_Plate},移至拍照检测位下", false, LogFlag);
                            //    return -1;
                            //}

                            List<SigleAxis> posList = new List<SigleAxis>();
                            //增加同步右工位X1轴与Y轴旋转到位
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标X1下,
                                pos = GlobalVar.motionConfig.scanSafeX1,
                                velrate = 1
                            });
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标X2上,
                                pos = GlobalVar.motionConfig.scanSafeX2,
                                velrate = 1
                            });

                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.贴标Y轴,
                                pos = GlobalVar.motionConfig.Down_checkPosY,
                                velrate = 1
                            });
                            var bres = GlobalMotion.toPostionMutil(posList);
                            TimeWatch($"{e_Plate},移至拍照检测位下", false, LogFlag);
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Label.拍照检测上:
                        {
                            var nres = -1;
                            TimeWatch($"{e_Plate},拍照检测上", true, LogFlag);
                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.未拍照;
                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.未拍照;
                            GlobalVar.IsPosBeforeLabel = false;
                            if (e_Plate == e_platePro.平台1)
                            {
                                if (GlobalVar.userConfig.IsLabelResultOk)
                                {
                                    GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                }
                                else
                                {
                                    //visionProc.CamIdx = 10;
                                    //GlobalVar.IsCheckTwo = false;
                                    //visionProc.curCameraPlate3 = e_CameraPlate.检测相机平台1;
                                    //GlobalVar.cameraList[(int)e_Camera.检测相机].softTrigger();
                                    //判断贴合是否正常1
                                    if (Station_LeftUPCameraPositionCheck(out string Result, out string meg) == 1)
                                    {
                                        if (Result.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                    }

                                }
                                // GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.定位相机触发, e_out_OnOff.on);
                                TimeWatch($"{e_Plate},拍照检测上", false, LogFlag);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                if (GlobalVar.userConfig.IsLabelResultOk)
                                {
                                    GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                }
                                else
                                {
                                    //visionProc.CamIdx = 10;
                                    //GlobalVar.IsCheckTwo = false;
                                    //visionProc.curCameraPlate3 = e_CameraPlate.检测相机平台2;
                                    //GlobalVar.cameraList[(int)e_Camera.检测相机].softTrigger();

                                    //判断贴合是否正常2
                                    if (Station_RightUPCameraPositionCheck(out string Result2, out string meg2) == 1)
                                    {
                                        if (Result2.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                    }

                                }

                                //GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.定位相机触发, e_out_OnOff.on);
                                TimeWatch($"{e_Plate},拍照检测上", false, LogFlag);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                if (GlobalVar.userConfig.IsLabelResultOk)
                                {
                                    GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                    GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                }
                                else
                                {
                                    //visionProc.CamIdx = 10;
                                    //GlobalVar.IsCheckTwo = true;
                                    //GlobalVar.cameraList[(int)e_Camera.检测相机].softTrigger();

                                    //判断贴合是否正常1
                                    if (Station_LeftUPCameraPositionCheck(out string Result, out string meg) == 1)
                                    {
                                        if (Result.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                    }

                                    //判断贴合是否正常2
                                    if (Station_RightUPCameraPositionCheck(out string Result2, out string meg2) == 1)
                                    {
                                        if (Result2.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                    }


                                }
                                TimeWatch($"{e_Plate},拍照检测上", false, LogFlag);
                                return 1;
                            }
                        }
                        break;
                    case e_Step_Label.拍照检测下:
                        {
                            var nres = -1;
                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.未拍照;
                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.未拍照;
                            GlobalVar.IsPosBeforeLabel = false;
                            TimeWatch($"{e_Plate},拍照检测下", true, LogFlag);
                            if (e_Plate == e_platePro.平台1)
                            {
                                if (GlobalVar.userConfig.IsLabelResultOk)
                                {
                                    GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                }
                                else
                                {
                                    //visionProc.CamIdx = 10;
                                    //GlobalVar.IsCheckTwo = false;
                                    //visionProc.curCameraPlate3 = e_CameraPlate.检测相机平台1;
                                    //GlobalVar.cameraList[(int)e_Camera.检测相机].softTrigger();
                                    //判断贴合是否正常1
                                    if (Station_LeftDownCameraPositionCheck(out string Result, out string meg) == 1)
                                    {
                                        if (Result.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                    }

                                }
                                // GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.定位相机触发, e_out_OnOff.on);
                                TimeWatch($"{e_Plate},拍照检测下", false, LogFlag);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                if (GlobalVar.userConfig.IsLabelResultOk)
                                {
                                    GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                }
                                else
                                {
                                    //visionProc.CamIdx = 10;
                                    //GlobalVar.IsCheckTwo = false;
                                    //visionProc.curCameraPlate3 = e_CameraPlate.检测相机平台2;
                                    //GlobalVar.cameraList[(int)e_Camera.检测相机].softTrigger();

                                    //判断贴合是否正常2
                                    if (Station_RightDownCameraPositionCheck(out string Result2, out string meg2) == 1)
                                    {
                                        if (Result2.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                    }

                                }

                                //GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.定位相机触发, e_out_OnOff.on);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                if (GlobalVar.userConfig.IsLabelResultOk)
                                {
                                    GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                    GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                }
                                else
                                {
                                    //visionProc.CamIdx = 10;
                                    //GlobalVar.IsCheckTwo = true;
                                    //GlobalVar.cameraList[(int)e_Camera.检测相机].softTrigger();

                                    
                                    //判断贴合是否正常2
                                    if (Station_LeftDownCameraPositionCheck(out string Result1, out string meg1) == 1)
                                    {
                                        if (Result1.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                    }
                                   
                                    if (Station_RightDownCameraPositionCheck(out string Result4, out string meg4) == 1)
                                    {
                                        if (Result4.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                    }

                                }
                                TimeWatch($"{e_Plate},拍照检测下", false, LogFlag);
                                return 1;
                            }
                        }
                        break;
                    case e_Step_Label.拍照复检:
                        {
                            var nres = -1;
                            TimeWatch($"{e_Plate},拍照复检", true, LogFlag);
                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.未拍照;
                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.未拍照;
                            GlobalVar.IsPosBeforeLabel = false;
                            if (e_Plate == e_platePro.平台1)
                            {
                                if (GlobalVar.userConfig.IsLabelResultOk)
                                {
                                    GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                }
                                else
                                {
                                    //visionProc.CamIdx = 10;
                                    //GlobalVar.IsCheckTwo = false;
                                    //visionProc.curCameraPlate3 = e_CameraPlate.检测相机平台1;
                                    //GlobalVar.cameraList[(int)e_Camera.检测相机].softTrigger();
                                    //判断贴合是否正常1
                                    if (Station_LeftCameraPositionCheck(out string Result, out string meg) == 1)
                                    {
                                        if (Result.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                    }

                                }
                                // GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.定位相机触发, e_out_OnOff.on);
                                TimeWatch($"{e_Plate},拍照复检", false, LogFlag);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                if (GlobalVar.userConfig.IsLabelResultOk)
                                {
                                    GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                }
                                else
                                {
                                    //visionProc.CamIdx = 10;
                                    //GlobalVar.IsCheckTwo = false;
                                    //visionProc.curCameraPlate3 = e_CameraPlate.检测相机平台2;
                                    //GlobalVar.cameraList[(int)e_Camera.检测相机].softTrigger();

                                    //判断贴合是否正常2
                                    if (Station_RightCameraPositionCheck(out string Result2, out string meg2) == 1)
                                    {
                                        if (Result2.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                    }

                                }

                                //GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.定位相机触发, e_out_OnOff.on);
                                TimeWatch($"{e_Plate},拍照复检", false, LogFlag);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                if (GlobalVar.userConfig.IsLabelResultOk)
                                {
                                    GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                    GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                }
                                else
                                {
                                    //visionProc.CamIdx = 10;
                                    //GlobalVar.IsCheckTwo = true;
                                    //GlobalVar.cameraList[(int)e_Camera.检测相机].softTrigger();

                                    //判断贴合是否正常1
                                    if (Station_LeftCameraPositionCheck(out string Result, out string meg) == 1)
                                    {
                                        if (Result.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check1 = e_Camera_Pos.已拍照NG;
                                    }

                                    //判断贴合是否正常2
                                    if (Station_RightCameraPositionCheck(out string Result2, out string meg2) == 1)
                                    {
                                        if (Result2.Contains("OK"))
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    else
                                    {
                                        GlobalVar.e_Camera_Check2 = e_Camera_Pos.已拍照NG;
                                    }


                                }
                                TimeWatch($"{e_Plate},拍照复检", false, LogFlag);
                                return 1;
                            }
                        }
                        break;
                    case e_Step_Label.移至NG取工装位上:
                        {
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, 0, 1, true);
                            if (!bres)
                                return -1;
                            bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, 0, 1, true);
                            if (!bres)
                                return -1;
                            bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Y轴, GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG取工装位].Y, 1, true);

                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Label.移至NG放工装位上:
                        {
                            if (e_Staus == e_MachineStatus.手动界面)
                            {
                                //如果Y方向要大于NG放料/拍照位时     平台1坐标X要在安全位以上
                                var y1 = Card_1.AxisList[(int)e_card1_axis.贴标Y轴].m_AxisSts.CurrPosi;
                                var NGy1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.NG放标位].Y;
                                var scany1 = GlobalVar.motionConfig.Plate1_pos[(int)e_Pos.拍照位].Y;
                                if (y1 > NGy1 || y1 > scany1)
                                {
                                    var x1 = Card_1.AxisList[(int)e_card1_axis.贴标X1下].m_AxisSts.CurrPosi;
                                    if (x1 > (GlobalVar.motionConfig.scanSafeX1 + SaftRange))
                                    {
                                        string msg = $"当前贴标模组 平台1不在安全位 上  {e_Step.ToString()}失败 ";
                                        MessageBox.Show(msg);
                                        displalyInfo.displayErrorMain(msg);
                                        return -1;
                                    }
                                }
                            }
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG放工装位].Zup, 1, true);
                            if (!bres)
                                return -1;
                            bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, GlobalVar.motionConfig.Plate2_pos[(int)e_Pos.拍照位].Z, 1, true);
                            if (!bres)
                                return -1;
                            bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Y轴, GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG放工装位].Y, 1, true);

                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Label.NG取工装位下降:
                        {
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG取工装位].Zdown, 1, true);
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Label.NG放工装位下降:
                        {
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG放工装位].Zdown, 1, true);
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Label.NG取工装位上升:
                        {
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG取工装位].Zup, 1, true);
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Label.NG放工装位上升:
                        {
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.剔除Z轴, GlobalVar.motionConfig.LaserNG_pos[(int)e_PosNG.NG放工装位].Zup, 1, true);
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Label.NG取工装吸真空:
                        {
                            var nres = -1;
                            var e_out = e_out_OnOff.off;
                            if (e_Plate == e_platePro.平台1)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品1, e_out);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品2, e_out);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品1, e_out);
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品2, e_out);
                                return 1;
                            }
                        }
                        break;
                    case e_Step_Label.NG放工装破真空:
                        {
                            var nres = -1;
                            var e_out = e_out_OnOff.on;
                            if (e_Plate == e_platePro.平台1)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品1, e_out);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {

                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品2, e_out);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品1, e_out);
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.NG真空吸产品2, e_out);
                                return 1;
                            }
                        }
                        break;
                    case e_Step_Label.飞达吹气:
                        {
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.飞达吹气1, e_out_OnOff.off);
                                    break;
                                case e_platePro.平台2:
                                    GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.飞达吹气2, e_out_OnOff.off);
                                    break;
                                case e_platePro.双平台有:
                                    GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.飞达吹气1, e_out_OnOff.off);
                                    GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.飞达吹气2, e_out_OnOff.off);
                                    break;
                            }
                            return 1;
                        }
                        break;
                    case e_Step_Label.飞达关气:
                        {
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.飞达吹气1, e_out_OnOff.on);
                                    break;
                                case e_platePro.平台2:
                                    GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.飞达吹气2, e_out_OnOff.on);
                                    break;
                                case e_platePro.双平台有:
                                    GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.飞达吹气1, e_out_OnOff.on);
                                    GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.飞达吹气2, e_out_OnOff.on);
                                    break;
                            }
                            return 1;
                        }
                        break;
                    case e_Step_Label.吸标NG旋转到取标位:
                        {
                            var nok = 1;
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台1取标抬起, true, e_input_extCard1.平台1吸标NG抬起到位, true);
                                        if (nok == 1)
                                        {
                                            nok = SetAir3(e_output_extCard1.平台1取标旋转, true, e_input_extCard1.平台1吸标NG取料位, true);
                                            Thread.Sleep(GlobalVar.userConfig.deleyNGRotate);
                                        }
                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台2取标抬起, true, e_input_extCard1.平台2吸标NG抬起到位, true);

                                        if (nok == 1)
                                        {
                                            nok = SetAir3(e_output_extCard1.平台2取标旋转, true, e_input_extCard1.平台2吸标NG取料位, true);
                                            Thread.Sleep(GlobalVar.userConfig.deleyNGRotate);
                                        }
                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        var nres1 = SetAir3(e_output_extCard1.平台1取标抬起, true, e_input_extCard1.平台1吸标NG抬起到位, true);
                                        var nres2 = SetAir3(e_output_extCard1.平台2取标抬起, true, e_input_extCard1.平台2吸标NG抬起到位, true);
                                        nok = (nres1 == 1 && nres2 == 1) ? 1 : -1;
                                        if (nok == 1)
                                        {
                                            nres1 = SetAir3(e_output_extCard1.平台1取标旋转, true, e_input_extCard1.平台1吸标NG取料位, true);
                                            nres2 = SetAir3(e_output_extCard1.平台2取标旋转, true, e_input_extCard1.平台2吸标NG取料位, true);
                                            Thread.Sleep(GlobalVar.userConfig.deleyNGRotate);
                                            nok = (nres1 == 1 && nres2 == 1) ? 1 : -1;
                                        }
                                    }
                                    break;

                            }
                            return nok;
                        }
                        break;
                    case e_Step_Label.吸标NG旋转到放标位:
                        {
                            var nok = 1;
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台1取标抬起, true, e_input_extCard1.平台1吸标NG抬起到位, true);
                                        if (nok == 1)
                                        {
                                            nok = SetAir3(e_output_extCard1.平台1取标旋转, false, e_input_extCard1.平台1吸标NG放料位, true);
                                            Thread.Sleep(GlobalVar.userConfig.deleyNGRotate);
                                        }
                                        //nok = 1;
                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台2取标抬起, true, e_input_extCard1.平台2吸标NG抬起到位, true);
                                        if (nok == 1)
                                        {
                                            nok = SetAir3(e_output_extCard1.平台2取标旋转, false, e_input_extCard1.平台2吸标NG放料位, true);
                                            Thread.Sleep(GlobalVar.userConfig.deleyNGRotate);
                                        }

                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        var nOK1 = SetAir3(e_output_extCard1.平台1取标抬起, true, e_input_extCard1.平台1吸标NG抬起到位, true);
                                        var nOK2 = SetAir3(e_output_extCard1.平台2取标抬起, true, e_input_extCard1.平台2吸标NG抬起到位, true);
                                        if (nOK1 == 1 && nOK2 == 1)
                                        {
                                            nOK1 = SetAir3(e_output_extCard1.平台1取标旋转, false, e_input_extCard1.平台1吸标NG放料位, true);
                                            nOK2 = SetAir3(e_output_extCard1.平台2取标旋转, false, e_input_extCard1.平台2吸标NG放料位, true);
                                            Thread.Sleep(GlobalVar.userConfig.deleyNGRotate);
                                        }
                                        nok = (nOK1 == 1 && nOK2 == 1) ? 1 : -1;
                                    }
                                    break;
                            }
                            return nok;
                        }
                        break;
                    case e_Step_Label.吸标NG下压:
                        {
                            var nok = 1;
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台1取标抬起, false, e_input_extCard1.平台1吸标NG抬起到位, false);
                                        Thread.Sleep(GlobalVar.userConfig.deleyNGup);
                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台2取标抬起, false, e_input_extCard1.平台2吸标NG抬起到位, false);
                                        Thread.Sleep(GlobalVar.userConfig.deleyNGup);

                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        var nOK1 = SetAir3(e_output_extCard1.平台1取标抬起, false, e_input_extCard1.平台1吸标NG抬起到位, false);
                                        var nOK2 = SetAir3(e_output_extCard1.平台2取标抬起, false, e_input_extCard1.平台2吸标NG抬起到位, false);
                                        Thread.Sleep(GlobalVar.userConfig.deleyNGup);
                                        nok = (nOK1 == 1 && nOK2 == 1) ? 1 : -1;
                                    }
                                    break;
                            }
                            return nok;
                        }
                        break;
                    case e_Step_Label.吸标NG抬起:
                        {
                            var nok = 1;
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台1取标抬起, true, e_input_extCard1.平台1吸标NG抬起到位, true);
                                      
                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        nok = SetAir3(e_output_extCard1.平台2取标抬起, true, e_input_extCard1.平台2吸标NG抬起到位, true);
                                       
                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        var nOK1 = SetAir3(e_output_extCard1.平台1取标抬起, true, e_input_extCard1.平台1吸标NG抬起到位, true);
                                        var nOK2 = SetAir3(e_output_extCard1.平台2取标抬起, true, e_input_extCard1.平台2吸标NG抬起到位, true);
                                       
                                        nok = (nOK1 == 1 && nOK2 == 1) ? 1 : -1;
                                    }
                                    break;
                            }
                            return nok;
                        }
                        break;
                    case e_Step_Label.吸标NG吸气:
                        {
                            var nok = 1;
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气1, e_out_OnOff.off);

                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气2, e_out_OnOff.off);
                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气1, e_out_OnOff.off);
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气2, e_out_OnOff.off);
                                    }
                                    break;
                            }
                            Thread.Sleep(GlobalVar.userConfig.deleyNGair);
                            return nok;
                        }
                        break;
                    case e_Step_Label.吸标NG破气:
                        {
                            var nok = 1;
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气1, e_out_OnOff.on);

                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气2, e_out_OnOff.on);

                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气1, e_out_OnOff.on);
                                        CardExt_1.setOut((ushort)e_output_extCard1.NG取标吸气2, e_out_OnOff.on);
                                    }
                                    break;
                            }
                            return nok;
                        }
                        break;

                    case e_Step_Label.贴标前定位拍照:
                        {
                            GlobalVar.IsPosBeforeLabel = true;
                            visionProc.CamIdx = 10;
                            TimeWatch($"{e_Plate},贴标前定位拍照", true, LogFlag);
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        GlobalVar.e_Camera_LabelPos1 = e_Camera_Pos.未拍照;
                                        GlobalVar.e_Camera_Cut1 = e_Camera_Pos.未拍照;

                                        //&判断是否已撕膜1 AND 获取偏差1
                                        VisionUP_LeftResultPlate = new xPostion();
                                        if (Station_LeftUPCameraTrigger(out VisionUP_LeftResultPlate.X, out VisionUP_LeftResultPlate.Y, out VisionUP_LeftResultPlate.Angle, out string meg2) == 1)
                                        {
                                            GlobalVar.e_Camera_Cut1 = e_Camera_Pos.已拍照OK;
                                            GlobalVar.e_Camera_LabelPos1 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Cut1 = e_Camera_Pos.已拍照NG;
                                            GlobalVar.e_Camera_LabelPos1 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        //判断是否已撕膜2与或取偏差2
                                        VisionUP_RightResultPlate = new xPostion();
                                        if (Station_RightUPCameraTrigger(out VisionUP_RightResultPlate.X, out VisionUP_RightResultPlate.Y, out VisionUP_RightResultPlate.Angle, out string meg4) == 1)
                                        {
                                            GlobalVar.e_Camera_Cut2 = e_Camera_Pos.已拍照OK;
                                            GlobalVar.e_Camera_LabelPos2 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Cut2 = e_Camera_Pos.已拍照NG;
                                            GlobalVar.e_Camera_LabelPos2 = e_Camera_Pos.已拍照NG;
                                        }
                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        GlobalVar.e_Camera_LabelPos1 = e_Camera_Pos.未拍照;
                                        GlobalVar.e_Camera_LabelPos2 = e_Camera_Pos.未拍照;
                                        GlobalVar.e_Camera_Cut1 = e_Camera_Pos.未拍照;
                                        GlobalVar.e_Camera_Cut2 = e_Camera_Pos.未拍照;
                                        #region 
                                        //&判断是否已撕膜1 AND 获取偏差1
                                        VisionUP_LeftResultPlate = new xPostion();
                                        if (Station_LeftUPCameraTrigger(out VisionUP_LeftResultPlate.X, out VisionUP_LeftResultPlate.Y, out VisionUP_LeftResultPlate.Angle, out string meg2) == 1)
                                        {
                                            GlobalVar.e_Camera_Cut1 = e_Camera_Pos.已拍照OK;
                                            GlobalVar.e_Camera_LabelPos1 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Cut1 = e_Camera_Pos.已拍照NG;
                                            GlobalVar.e_Camera_LabelPos1 = e_Camera_Pos.已拍照NG;
                                        }

                                        //判断是否已撕膜2与或取偏差2
                                        VisionUP_RightResultPlate = new xPostion();
                                        if (Station_RightUPCameraTrigger(out VisionUP_RightResultPlate.X, out VisionUP_RightResultPlate.Y, out VisionUP_RightResultPlate.Angle, out string meg4) == 1)
                                        {
                                            GlobalVar.e_Camera_Cut2 = e_Camera_Pos.已拍照OK;
                                            GlobalVar.e_Camera_LabelPos2 = e_Camera_Pos.已拍照OK;
                                        }
                                        else
                                        {
                                            GlobalVar.e_Camera_Cut2 = e_Camera_Pos.已拍照NG;
                                            GlobalVar.e_Camera_LabelPos2 = e_Camera_Pos.已拍照NG;
                                        }
                                        #endregion
                                    }
                                    break;
                            }
                            TimeWatch($"{e_Plate},贴标前定位拍照", false, LogFlag);
                            return 1;
                        }
                        break;
                    case e_Step_Label.文字版快换气缸松开:
                        {
                            var nok = 1;
                            DialogResult Rst=  MessageBox.Show($"请确认是否松开{e_Plate}夹爪气缸","提示",MessageBoxButtons.YesNo);
                            if(Rst!= DialogResult.Yes)
                            {
                                return nok;
                            }
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        nok = SetAir4(e_output_extCard1.吸标靶面快换夹具1, true);
                                        Thread.Sleep(GlobalVar.userConfig.deleyNGup);
                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        nok = SetAir4(e_output_extCard1.吸标靶面快换夹具2, true);
                                        Thread.Sleep(GlobalVar.userConfig.deleyNGup);
                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        var nOK1 = SetAir4(e_output_extCard1.吸标靶面快换夹具1, true);
                                        var nOK2 = SetAir4(e_output_extCard1.吸标靶面快换夹具2, true);
                                        Thread.Sleep(GlobalVar.userConfig.deleyNGup);
                                        nok = (nOK1 == 1 && nOK2 == 1) ? 1 : -1;
                                    }
                                    break;
                            }
                            return nok;
                        }
                        break;
                    case e_Step_Label.文字版快换气缸夹紧:
                        {
                            var nok = 1;
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    {
                                        nok = SetAir4(e_output_extCard1.吸标靶面快换夹具1, false);
                                        Thread.Sleep(GlobalVar.userConfig.deleyNGup);
                                    }
                                    break;
                                case e_platePro.平台2:
                                    {
                                        nok = SetAir4(e_output_extCard1.吸标靶面快换夹具2, false);
                                        Thread.Sleep(GlobalVar.userConfig.deleyNGup);
                                    }
                                    break;
                                case e_platePro.双平台有:
                                    {
                                        var nOK1 = SetAir4(e_output_extCard1.吸标靶面快换夹具1, false);
                                        var nOK2 = SetAir4(e_output_extCard1.吸标靶面快换夹具2, false);
                                        Thread.Sleep(GlobalVar.userConfig.deleyNGup);
                                        nok = (nOK1 == 1 && nOK2 == 1) ? 1 : -1;
                                    }
                                    break;
                            }
                            return nok;
                        }
                        break;


                }
                return -1;
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Step_Labeling" + ex.Message);
                return -1;
            }
        }
        public static double VarXYR = 2.20;
        public static int SetAirTimeOut = 2000;


        public static int Step_XYZR(double X, double Y, double Z, double R, bool isAbs = false)
        {
            int nRes = -1;
            try
            {
                //Z轴先移到安全拍照位
                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, Z, 1, true);
                if (!bres)
                    return -1;

                //同步移动XYR
                List<SigleAxis> posList = new List<SigleAxis>();
                posList.Add(new SigleAxis()
                {
                    IsAbs = isAbs,
                    nAxis = (int)e_card1_axis.贴标R1下,
                    pos = R,
                    velrate = 1
                });
                posList.Add(new SigleAxis()
                {
                    IsAbs = isAbs,
                    nAxis = (int)e_card1_axis.贴标X1下,
                    pos = X,
                    velrate = 1
                });
                posList.Add(new SigleAxis()
                {
                    IsAbs = isAbs,
                    nAxis = (int)e_card1_axis.贴标Y轴,
                    pos = Y,
                    velrate = 1
                });
                bres = GlobalMotion.toPostionMutil(posList);

                return bres ? 1 : -1;
            }
            catch (Exception)
            {
                return -1;
            }
        }

        public static int Step_XYZR2(double X, double Y, double Z, double R, bool isAbs = false)
        {
            int nRes = -1;
            try
            {
                //Z轴先移到安全拍照位
                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.贴标Z轴, Z, 1, true);
                if (!bres)
                    return -1;

                //同步移动XYR
                List<SigleAxis> posList = new List<SigleAxis>();
                posList.Add(new SigleAxis()
                {
                    IsAbs = isAbs,
                    nAxis = (int)e_card1_axis.贴标R2上,
                    pos = R,
                    velrate = 1
                });
                posList.Add(new SigleAxis()
                {
                    IsAbs = isAbs,
                    nAxis = (int)e_card1_axis.贴标X2上,
                    pos = X,
                    velrate = 1
                });
                posList.Add(new SigleAxis()
                {
                    IsAbs = isAbs,
                    nAxis = (int)e_card1_axis.贴标Y轴,
                    pos = Y,
                    velrate = 1
                });
                bres = GlobalMotion.toPostionMutil(posList);

                return bres ? 1 : -1;
            }
            catch (Exception)
            {
                return -1;
            }
        }


        #region  //海康相机TCP交互接口
        static object Ocr_Object = new object();

        /// <summary>
        /// 文字版C0C1 识别
        /// </summary>
        /// <param name="e_Plate"></param>
        /// <param name="Result"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Camera_OCR(e_platePro e_Plate, out string Result, out string meg)
        {
            lock (Ocr_Object)
            {
                int Rts = 0;
                string cmd = "";
                string station_str = "";
                Result = "";
                meg = "";

                try
                {
                    switch (e_Plate)
                    {
                        case e_platePro.平台1:
                            cmd = $"A1";
                            station_str = "相机左工位识别拍照";
                            break;

                        case e_platePro.平台2:
                            cmd = $"A2";
                            station_str = "相机右工位识别拍照";
                            break;
                    }
                    for (int i = 0; i < 3; i++)
                    {
                        Thread.Sleep(500);
                        displalyInfo.displayInfoMain($"{station_str}发送指令：" + cmd);
                        GlobalVar.VisionTcpIP.SendData(cmd);
                        Thread.Sleep(500);
                        if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                        {
                            displalyInfo.displayInfoMain($"{station_str}返回指令：" + command);
                            if (command.Contains("OK"))
                            {
                                string[] str_buf = command.Split(new char[] { ',' });
                                if (str_buf != null && str_buf.Length > 2)
                                {
                                    Result = str_buf[2];
                                    Rts = 1;
                                    break;
                                }
                            }
                            else
                            {
                                meg = $"{station_str}返回指令NG：{ command} ";
                                Rts = -1;
                            }
                        }
                        else
                        {
                            Rts = -1;
                            meg = $"{station_str}返回指令超时。";
                            displalyInfo.displayInfoMain($"{station_str}返回指令超时。" + command);
                        }
                    }

                    return Rts;
                }
                catch (Exception er)
                {
                    meg = $"{station_str}发送或返回异常：" + er.ToString();
                    displalyInfo.displayInfoMain(meg);
                    return -1;
                }
            }
        }

        /// <summary>
        /// 下相机左右工位定位拍照
        /// </summary>
        /// <param name="e_Plate"></param>
        /// <param name="Camera_X"></param>
        /// <param name="Camera_Y"></param>
        /// <param name="Camera_R"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Station_DownCameraTrigger(e_platePro e_Plate, out double Camera_X, out double Camera_Y, out double Camera_R, out string meg)
        {
            int Rts = 0;
            Camera_X = 0;
            Camera_Y = 0;
            Camera_R = 0;
            string cmd = "";
            string station_str = "";
            meg = "";

            try
            {
                switch (e_Plate)
                {
                    case e_platePro.平台1:
                        cmd = $"T1";
                        station_str = "左相机工位定位拍照";
                        break;

                    case e_platePro.平台2:
                        cmd = $"T3";
                        station_str = "右相机工位定位拍照";
                        break;
                }
                //Thread.Sleep(500);
                for (int i = 0; i < 1; i++)
                {
                    displalyInfo.displayInfoMain($"{station_str}发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"{station_str}返回指令：" + command);
                        if (command.Contains("OK"))
                        {
                            string[] str_buf = command.Split(new char[] { ',' });
                            if (str_buf != null && str_buf.Length > 2)
                            {
                                double.TryParse(str_buf[2], out Camera_X);
                                double.TryParse(str_buf[3], out Camera_Y);
                                double.TryParse(str_buf[4], out Camera_R);
                                Rts = 1;
                                break;
                            }
                        }
                        else
                        {
                            meg = $"{station_str}返回指令NG：{ command} ";
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = $"{station_str}返回指令超时。";
                        displalyInfo.displayInfoMain($"{station_str}返回指令超时。" + command);
                        Rts = -1;
                    }
                }

                return Rts;
            }
            catch (Exception er)
            {
                meg = $"{station_str}指令发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }

        }


        /// <summary>
        /// 左上相机定位拍照
        /// </summary>
        /// <param name="Camera_X"></param>
        /// <param name="Camera_Y"></param>
        /// <param name="Camera_R"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Station_LeftUPCameraTrigger(out double Camera_X, out double Camera_Y, out double Camera_R, out string meg)
        {
            int Rts = 0;
            Camera_X = 0;
            Camera_Y = 0;
            Camera_R = 0;
            string cmd = "";
            meg = "";

            try
            {
               
                for (int i = 0; i < 3; i++)
                {
                    cmd = $"T2";
                    //Thread.Sleep(500);
                    displalyInfo.displayInfoMain($"左上相机定位拍照发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    //Thread.Sleep(500);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"左上相机定位拍照返回指令：" + command);
                        string[] str_buf = command.Split(new char[] { ',' });
                        if (str_buf != null && str_buf.Length > 2)
                        {
                            if (str_buf[1].Contains("OK"))
                            {
                                Rts = 1;
                                if (str_buf[2].Contains("OK"))
                                {
                                    double.TryParse(str_buf[3], out Camera_X);
                                    double.TryParse(str_buf[4], out Camera_Y);
                                    double.TryParse(str_buf[5], out Camera_R);
                                    Rts = 1;
                                    break;
                                }
                            }
                            else
                            {
                                Rts = -2;
                                break;
                            }
                        }
                        else
                        {
                            meg = "左上相机定位拍照返回指令格式不正确。";
                            displalyInfo.displayInfoMain($"左上相机定位拍照返回指令格式不正确。" + command);
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "左上相机定位拍照返回指令超时。";
                        displalyInfo.displayInfoMain($"左上相机定位拍照返回指令超时。" + command);
                        Rts = -1;
                    }
                }

                return Rts;
            }
            catch (Exception er)
            {
                meg = "左上相机定位拍照指令发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }

        }

        /// <summary>
        /// 右上相机定位拍照
        /// </summary>
        /// <param name="Camera_X"></param>
        /// <param name="Camera_Y"></param>
        /// <param name="Camera_R"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Station_RightUPCameraTrigger(out double Camera_X, out double Camera_Y, out double Camera_R, out string meg)
        {
            int Rts = 0;
            Camera_X = 0;
            Camera_Y = 0;
            Camera_R = 0;
            string cmd = "";
            meg = "";

            try
            {
                //Thread.Sleep(9000);
                for (int i = 0; i < 3; i++)
                {
                    cmd = $"T4";
                    //Thread.Sleep(100);
                    displalyInfo.displayInfoMain($"右上相机定位拍照发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    //Thread.Sleep(500);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"右上相机定位拍照返回指令：" + command);

                        string[] str_buf = command.Split(new char[] { ',' });
                        if (str_buf != null && str_buf.Length > 2)
                        {
                            if (str_buf[1].Contains("OK"))
                            {
                                Rts = 1;
                                if (str_buf[2].Contains("OK"))
                                {
                                    double.TryParse(str_buf[3], out Camera_X);
                                    double.TryParse(str_buf[4], out Camera_Y);
                                    double.TryParse(str_buf[5], out Camera_R);
                                    Rts = 1;
                                    break;
                                }
                            }
                            else
                            {
                                Rts = -2;
                                break;
                            }
                        }
                        else
                        {
                            meg = "右上相机定位拍照返回指令格式不正确。";
                            displalyInfo.displayInfoMain($"右上相机定位拍照返回指令格式不正确。" + command);
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "右上相机定位拍照返回指令超时。";
                        displalyInfo.displayInfoMain($"右上相机定位拍照返回指令超时。" + command);
                        Rts = -1;
                    }
                }
                return Rts;
            }
            catch (Exception er)
            {
                meg = "右上相机定位拍照指令发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }

        }
        /// <summary>
        /// 左相机定位复检
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Station_LeftCameraPositionCheck(out string Result, out string meg)
        {
            int Rts = 0;
            string cmd = "";
            Result = "";
            meg = "";

            try
            {
                for (int i = 0; i < 1; i++)
                {
                    cmd = $"S1";
                    //Thread.Sleep(500);
                    displalyInfo.displayInfoMain($"定位复检发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    //Thread.Sleep(500);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"定位复检返回指令：" + command);
                        if (command.Contains("OK"))
                        {
                            string[] str_buf = command.Split(new char[] { ',' });
                            if (str_buf != null && str_buf.Length > 1)
                            {
                                Result = str_buf[1];
                                Rts = 1;
                                break;
                            }
                        }
                        else
                        {
                            meg = $"定位复检返回指令NG：{ command} ";
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "定位复检返回指令超时。";
                        displalyInfo.displayInfoMain($"定位复检返回指令超时。" + command);
                        Rts = -1;
                    }
                    Thread.Sleep(500);
                }

                return Rts;

            }
            catch (Exception er)
            {
                meg = "定位复检指令发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }

        }
        /// <summary>
        /// 右相机定位复检
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Station_RightCameraPositionCheck(out string Result, out string meg)
        {
            int Rts = 0;
            string cmd = "";
            Result = "";
            meg = "";

            try
            {
                for (int i = 0; i < 1; i++)
                {
                    cmd = $"S3";
                    //Thread.Sleep(500);
                    displalyInfo.displayInfoMain($"定位复检发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    //Thread.Sleep(500);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"定位复检返回指令：" + command);
                        if (command.Contains("OK"))
                        {
                            string[] str_buf = command.Split(new char[] { ',' });
                            if (str_buf != null && str_buf.Length > 1)
                            {
                                Result = str_buf[1];
                                Rts = 1;
                                break;
                            }
                        }
                        else
                        {
                            meg = $"定位复检返回指令NG：{ command} ";
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "定位复检返回指令超时。";
                        displalyInfo.displayInfoMain($"定位复检返回指令超时。" + command);
                        Rts = -1;
                    }
                    Thread.Sleep(500);
                }

                return Rts;

            }
            catch (Exception er)
            {
                meg = "定位复检指令发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }

        }
        /// <summary>
        /// 左上相机定位复检
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Station_LeftUPCameraPositionCheck(out string Result, out string meg)
        {
            int Rts = 0;
            string cmd = "";
            Result = "";
            meg = "";

            try
            {
                for (int i = 0; i < 1; i++)
                {
                    cmd = $"S1";
                    //Thread.Sleep(500);
                    displalyInfo.displayInfoMain($"定位复检发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    //Thread.Sleep(500);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"定位复检返回指令：" + command);
                        if (command.Contains("OK"))
                        {
                            string[] str_buf = command.Split(new char[] { ',' });
                            if (str_buf != null && str_buf.Length > 1)
                            {
                                Result = str_buf[1];
                                Rts = 1;
                                break;
                            }
                        }
                        else
                        {
                            meg = $"定位复检返回指令NG：{ command} ";
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "定位复检返回指令超时。";
                        displalyInfo.displayInfoMain($"定位复检返回指令超时。" + command);
                        Rts = -1;
                    }
                    Thread.Sleep(500);
                }

                return Rts;

            }
            catch (Exception er)
            {
                meg = "定位复检指令发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }

        }

        /// <summary>
        /// 左下相机定位复检
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Station_LeftDownCameraPositionCheck(out string Result, out string meg)
        {
            int Rts = 0;
            string cmd = "";
            Result = "";
            meg = "";

            try
            {
                for (int i = 0; i < 1; i++)
                {
                    cmd = $"S2";
                    //Thread.Sleep(500);
                    displalyInfo.displayInfoMain($"定位复检发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    //Thread.Sleep(500);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"定位复检返回指令：" + command);
                        if (command.Contains("OK"))
                        {
                            string[] str_buf = command.Split(new char[] { ',' });
                            if (str_buf != null && str_buf.Length > 1)
                            {
                                Result = str_buf[1];
                                Rts = 1;
                                break;
                            }
                        }
                        else
                        {
                            meg = $"定位复检返回指令NG：{ command} ";
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "定位复检返回指令超时。";
                        displalyInfo.displayInfoMain($"定位复检返回指令超时。" + command);
                        Rts = -1;
                    }
                    Thread.Sleep(500);
                }

                return Rts;

            }
            catch (Exception er)
            {
                meg = "定位复检指令发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }

        }

        /// <summary>
        /// 右上相机定位复检
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Station_RightUPCameraPositionCheck(out string Result, out string meg)
        {
            int Rts = 0;
            string cmd = "";
            Result = "";
            meg = "";

            try
            {
                for (int i = 0; i < 1; i++)
                {
                    cmd = $"S3";
                    //Thread.Sleep(500);
                    displalyInfo.displayInfoMain($"定位复检发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    //Thread.Sleep(500);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"定位复检返回指令：" + command);
                        if (command.Contains("OK"))
                        {
                            string[] str_buf = command.Split(new char[] { ',' });
                            if (str_buf != null && str_buf.Length > 1)
                            {
                                Result = str_buf[1];
                                Rts = 1;
                                break;
                            }
                        }
                        else
                        {
                            meg = $"定位复检返回指令NG：{ command} ";
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "定位复检返回指令超时。";
                        displalyInfo.displayInfoMain($"定位复检返回指令超时。" + command);
                        Rts = -1;
                    }
                    Thread.Sleep(500);
                }

                return Rts;

            }
            catch (Exception er)
            {
                meg = "定位复检指令发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }

        }
        /// <summary>
        /// 右下相机定位复检
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Station_RightDownCameraPositionCheck(out string Result, out string meg)
        {
            int Rts = 0;
            string cmd = "";
            Result = "";
            meg = "";

            try
            {
                for (int i = 0; i < 1; i++)
                {
                    cmd = $"S4";
                    //Thread.Sleep(500);
                    displalyInfo.displayInfoMain($"定位复检发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    //Thread.Sleep(100);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"定位复检返回指令：" + command);
                        if (command.Contains("OK"))
                        {
                            string[] str_buf = command.Split(new char[] { ',' });
                            if (str_buf != null && str_buf.Length > 1)
                            {
                                Result = str_buf[1];
                                Rts = 1;
                                break;
                            }
                        }
                        else
                        {
                            meg = $"定位复检返回指令NG：{ command} ";
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "定位复检返回指令超时。";
                        displalyInfo.displayInfoMain($"定位复检返回指令超时。" + command);
                        Rts = -1;
                    }
                    Thread.Sleep(500);
                }

                return Rts;

            }
            catch (Exception er)
            {
                meg = "定位复检指令发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }

        }

        /// <summary>
        /// 上相机同步发送开始复检指令 下
        /// </summary>
        /// <returns></returns>
        public static int UpDown_SendData2(e_platePro e_Plate)
        {
            try
            {
                switch (e_Plate)
                {
                    case e_platePro.平台1:
                        GlobalVar.VisionTcpIP.SendData2("S2");
                        Thread.Sleep(130);
                        break;
                    case e_platePro.平台2:
                        GlobalVar.VisionTcpIP.SendData2("S4");
                        Thread.Sleep(130);
                        break;
                    case e_platePro.双平台有:
                        GlobalVar.VisionTcpIP.SendData2("S2");
                        Thread.Sleep(50);
                        GlobalVar.VisionTcpIP.SendData2("S4");
                        Thread.Sleep(130);
                        break;
                }

                return 1;
            }
            catch (Exception)
            {
                return -1;
            }
        }

        /// <summary>
        /// 上相机同步发送开始复检指令 上   并过去4个结果
        ///  LeftResult[0]:S1:左上；RightResult[0]:S3右上
        ///  LeftResult[1]:S2:左下；RightResult[1]:S4:右下
        /// </summary>
        /// <param name="DownResult"></param>
        /// <param name="UPResult"></param>
        /// <returns></returns>
        public static int UpDown_SendData3(e_platePro e_Plate,out bool[] LeftResult, out bool[] RightResult)
        {
            LeftResult = new bool[2] { false, false };
            RightResult = new bool[2] { false, false };
            bool[] result = new bool[4];
            string[] Bufstr = new string[4] { "S1,OK", "S2,OK", "S3,OK", "S4,OK" };

            try
            {
                switch (e_Plate)
                {
                    case e_platePro.平台1:
                        GlobalVar.VisionTcpIP.SendData2("S1");
                        Thread.Sleep(130);
                        break;
                    case e_platePro.平台2:
                        GlobalVar.VisionTcpIP.SendData2("S3");
                        Thread.Sleep(130);
                        break;
                    case e_platePro.双平台有:
                        GlobalVar.VisionTcpIP.SendData2("S1");
                        Thread.Sleep(50);
                        GlobalVar.VisionTcpIP.SendData2("S3");
                        Thread.Sleep(130);
                        break;
                }

                Thread.Sleep(300);
                GlobalVar.VisionTcpIP.GetData(out string data, out string mes);
                if (data!=string.Empty)
                {
                    displalyInfo.displayInfoMain($"复检发送指令返回成功："+ data);
                    string[] str = data.Split(new string[] { "\r\n" },StringSplitOptions.None);
                    if (str != null)
                    {
                        for (int K = 0; K < Bufstr.Length; K++)
                        {
                            for (int i = 0; i < str.Length; i++)
                            {
                                if (Bufstr[K].Contains(str[i]))
                                {
                                    result[K] = true;
                                    break;
                                }
                                else
                                {
                                    result[K] = false;
                                }
                            }
                        }

                    }
                    else
                    {
                        LeftResult = new bool[2] { false, false };
                        RightResult = new bool[2] { false, false };
                        return 1;
                    }
                }
                else
                {
                    LeftResult = new bool[2] { false, false };
                    RightResult = new bool[2] { false, false };
                    displalyInfo.displayInfoMain($"复检发送指令返回超时：" + mes);
                    return 1;
                }

                //LeftResult = new bool[2] { true, true };
                //RightResult = new bool[2] { true, true };

                LeftResult = new bool[2] { result[0], result[1] };
                RightResult = new bool[2] { result[2], result[3] };
                return 1;
            }
            catch (Exception)
            {
                LeftResult = new bool[2] { false, false };
                RightResult = new bool[2] { false, false };
                return -1;
            }
        }



        /// <summary>
        /// 左上相机手撕位复检
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Station_LeftUPCameraHandTearPositionInspection(out string Result, out string meg)
        {
            int Rts = 0;
            string cmd = "";
            Result = "";
            meg = "";

            try
            {
                for (int i = 0; i < 3; i++)
                {
                    cmd = $"K1";
                    Thread.Sleep(500);
                    displalyInfo.displayInfoMain($"左上相机手撕位复检发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    Thread.Sleep(500);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"左上相机手撕位复检返回指令：" + command);
                        if (command.Contains("OK"))
                        {
                            string[] str_buf = command.Split(new char[] { ',' });
                            if (str_buf != null && str_buf.Length > 2)
                            {
                                Result = str_buf[1];
                                Rts = 1;
                                break;
                            }
                        }
                        else
                        {
                            meg = $"左上相机手撕位复检返回指令NG：{ command} ";
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "左上相机手撕位复检返回指令超时。";
                        displalyInfo.displayInfoMain($"左上相机手撕位复检返回指令超时。" + command);
                        Rts = -1;
                    }
                }

                return 1;

            }
            catch (Exception er)
            {
                meg = "左上相机手撕位复检指令发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }
        }

        /// <summary>
        /// 右上相机手撕位复检
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int Station_RightUPCameraHandTearPositionInspection(out string Result, out string meg)
        {
            int Rts = 0;
            string cmd = "";
            Result = "";
            meg = "";

            try
            {
                for (int i = 0; i < 3; i++)
                {
                    cmd = $"K2";
                    Thread.Sleep(500);
                    displalyInfo.displayInfoMain($"右上相机手撕位复检发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    Thread.Sleep(500);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"右上相机手撕位复检返回指令：" + command);
                        if (command.Contains("OK"))
                        {
                            string[] str_buf = command.Split(new char[] { ',' });
                            if (str_buf != null && str_buf.Length > 2)
                            {
                                Result = str_buf[1];
                                Rts = 1;
                                break;
                            }
                        }
                        else
                        {
                            meg = $"右上相机手撕位复检返回指令NG：{ command} ";
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "右上相机手撕位复检返回指令超时。";
                        displalyInfo.displayInfoMain($"右上相机手撕位复检返回指令超时。" + command);
                        Rts = -1;
                    }
                }

                return Rts;

            }
            catch (Exception er)
            {
                meg = "右上相机手撕位复检指令发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }
        }

        /// <summary>
        /// 下相机关联
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int DownCameraRelation(out string Result, out string meg)
        {
            int Rts = 0;
            string cmd = "";
            Result = "";
            meg = "";

            try
            {
                for (int i = 0; i < 3; i++)
                {
                    cmd = $"C02";
                    Thread.Sleep(500);
                    displalyInfo.displayInfoMain($"下相机关联发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    Thread.Sleep(500);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"下相机关联返回指令：" + command);
                        if (command.Contains("OK"))
                        {
                            string[] str_buf = command.Split(new char[] { ',' });
                            if (str_buf != null && str_buf.Length > 2)
                            {
                                Result = str_buf[1];
                                Rts = 1;
                                break;
                            }
                        }
                        else
                        {
                            meg = $"下相机关联返回指令NG：{ command} ";
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "下相机关联返回指令超时。";
                        displalyInfo.displayInfoMain($"下相机关联返回指令超时。" + command);
                        Rts = -1;
                    }
                }

                return Rts;

            }
            catch (Exception er)
            {
                meg = "下相机关联发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }
        }

        /// <summary>
        /// 上相机关联
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="meg"></param>
        /// <returns></returns>
        public static int UPCameraRelation(out string Result, out string meg)
        {
            int Rts = 0;
            string cmd = "";
            Result = "";
            meg = "";

            try
            {
                for (int i = 0; i < 3; i++)
                {
                    cmd = $"C04";
                    Thread.Sleep(500);
                    displalyInfo.displayInfoMain($"上相机关联发送指令：" + cmd);
                    GlobalVar.VisionTcpIP.SendData(cmd);
                    Thread.Sleep(500);
                    if (GlobalVar.VisionTcpIP.GetData(out string command, out string mes) == 0)
                    {
                        displalyInfo.displayInfoMain($"上相机关联返回指令：" + command);
                        if (command.Contains("OK"))
                        {
                            string[] str_buf = command.Split(new char[] { ',' });
                            if (str_buf != null && str_buf.Length > 2)
                            {
                                Result = str_buf[1];
                                Rts = 1;
                                break;
                            }
                        }
                        else
                        {
                            meg = $"上相机关联返回指令NG：{ command} ";
                            Rts = -1;
                        }
                    }
                    else
                    {
                        meg = "上相机关联返回指令超时。";
                        displalyInfo.displayInfoMain($"下相机关联返回指令超时。" + command);
                        Rts = -1;
                    }
                }
                return Rts;

            }
            catch (Exception er)
            {
                meg = "上相机关联发送或返回异常：" + er.ToString();
                displalyInfo.displayInfoMain(meg);
                return -1;
            }
        }

        static object Source = new object();
        /// <summary>
        /// 光源控制
        /// </summary>
        /// <param name="Port"></param>
        /// <param name="State"></param>
        public static void LightSourceControl(int Port, bool State)
        {
            lock (Source)
            {
                try
                {
                    Task.Run(() =>
                    {
                        string CMD = "";
                        if (State)
                        {
                            CMD = "$F" + Port.ToString() + "=1#";
                        }
                        else
                        {
                            CMD = "$F" + Port.ToString() + "=0#";
                        }
                        for (int i = 0; i < 3; i++)
                        {
                            GlobalVar.LightSourceController.Writeport_string(CMD);
                            Thread.Sleep(800);
                            string str = GlobalVar.LightSourceController.Readport_string();
                            if (str.Contains("OK") || str.Contains("O") || str.Contains("o") || str.Contains("K") || str.Contains("k"))
                            {
                                displalyInfo.displayInfoMain($"光源控制成功：" + CMD);
                                return;
                            }
                            else
                            {
                                displalyInfo.displayInfoMain($"光源控制失败：" + CMD);
                            }
                            Thread.Sleep(500);
                        }
                    });
                }
                catch (Exception)
                {
                    ;
                }
            }
        }


        #endregion






        /// <summary>
        /// 设置IO信号
        /// </summary>
        /// <param name="e_output"></param>
        /// <param name="heigh_out"></param>
        /// <param name="e_input"></param>
        /// <param name="heigh_in"></param>
        /// <returns></returns>
        public static int SetAir(e_output_extCard2 e_output, bool heigh_out, e_input_extCard2 e_input, bool heigh_in)
        {
            try
            {
                GlobalMotion.CardExt_2.setOut((ushort)e_output, (heigh_out ? e_out_OnOff.off : e_out_OnOff.on));//信号取反
                Stopwatch sw = new Stopwatch();
                sw.Restart();
                while (true)
                {
                    if (Input_CardEx2[(int)e_input] == heigh_in)//信号取反
                        return 1;
                    if (sw.ElapsedMilliseconds > SetAirTimeOut)
                        return -1;
                }
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        public static int SetAir2(e_output_extCard2 e_output, bool heigh_out, e_input_extCard1 e_input, bool heigh_in)
        {
            try
            {
                GlobalMotion.CardExt_2.setOut((ushort)e_output, (heigh_out ? e_out_OnOff.off : e_out_OnOff.on));//信号取反
                Stopwatch sw = new Stopwatch();
                sw.Restart();
                while (true)
                {
                    if (Input_CardEx1[(int)e_input] == heigh_in)//信号取反
                        return 1;
                    if (sw.ElapsedMilliseconds > SetAirTimeOut)
                        return -1;
                }
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        public static int SetAirTimeOut3 = 5000;
        public static int SetAir3(e_output_extCard1 e_output, bool heigh_out, e_input_extCard1 e_input, bool heigh_in)
        {
            try
            {
                GlobalMotion.CardExt_1.setOut((ushort)e_output, (heigh_out ? e_out_OnOff.off : e_out_OnOff.on));//信号取反
                Stopwatch sw = new Stopwatch();
                sw.Restart();
                while (true)
                {
                    if (Input_CardEx1[(int)e_input] == heigh_in)//信号取反
                        return 1;
                    if (sw.ElapsedMilliseconds > SetAirTimeOut3)
                        return -1;
                }
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        public static int SetAir4(e_output_extCard1 e_output, bool heigh_out)
        {
            try
            {
                GlobalMotion.CardExt_1.setOut((ushort)e_output, (heigh_out ? e_out_OnOff.off : e_out_OnOff.on));//信号取反
                //Stopwatch sw = new Stopwatch();
                //sw.Restart();
                //while (true)
                //{
                //    if (Input_CardEx1[(int)e_input] == heigh_in)//信号取反
                //        return 1;
                //    if (sw.ElapsedMilliseconds > SetAirTimeOut3)
                //        return -1;
                //}
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        #region 步骤计时和LOG打印

        public const string LogPath = "D:\\CTLog\\";
        public static object lockCT = new object();
        public static void WriteCTLog(string message)
        {
            string Dir = LogPath + $"\\Log\\" + DateTime.Today.ToString("yyyyMMdd") + "\\" + DateTime.Now.ToString("HH");
            string path = Dir + "\\"  + "CT.txt";

            message = DateTime.Now.ToString("HH:mm:ss:fff") + "= > " + message;

            if (!Directory.Exists(Dir))
            {
                Directory.CreateDirectory(Dir);
            }
            lock (lockCT)
            {
                try
                {
                    FileStream fs;
                    if (!File.Exists(path))
                    {
                        fs = new FileStream(path, FileMode.OpenOrCreate);
                    }
                    else
                    {
                        fs = new FileStream(path, FileMode.Append);
                    }
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine(message);
                    sw.Close();
                    fs.Close();
                }
                catch (Exception)
                {
                }

            }
        }

        public static Dictionary<string, Stopwatch> TimeDictionary = new Dictionary<string, Stopwatch>();
        public static void TimeWatch(string str, bool flag, bool needWatch = false)
        {
            //后续添加的标志位，用于返回不需要计时的方法
            try
            {
                if (!needWatch)
                {
                    return;
                }

                if (flag)
                {
                    if (!TimeDictionary.ContainsKey(str))
                    {
                        Stopwatch sw = new Stopwatch();
                        TimeDictionary.Add(str, sw);
                        sw.Start();
                        WriteCTLog($"{str} 开始计时--------------------------------------------");
                    }
                }
                else
                {
                    if (TimeDictionary.ContainsKey(str))
                    {
                        Stopwatch sw = TimeDictionary[str];
                        sw.Stop();
                        long elapsedTime = sw.ElapsedMilliseconds;
                        sw.Reset();
                        TimeDictionary.Remove(str);

                        WriteCTLog($"{str} 结束时间：{elapsedTime}ms -------------------------------------");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
           
        }

        #endregion


    }

    #region enum define
    public enum e_MachineStatus
    {
        无控制,
        暂停控制,
        异常急停,
        手动界面
    }
    public enum e_Step_Cut
    {
        移至撕膜等料位,
        移至撕膜水平位,
        移至夹膜位,
        夹住膜,
        移至撕膜终点位,
        移至撕膜过度位,
        移至撕膜垃圾位,
        松开膜,
        吹气除膜,
        吹气除尘,
        下降压住产品,
        上升松开产品,
        Z轴上下动
    }
    public enum e_Flow_Cut
    {
        等待有工装到达,
        读卡器读数据,
        执行撕膜准备工作,
        撕膜,
        撕膜完成,
        放行治具

    }
    public enum e_Mutil_step
    {
        移至取标位取标,
        等待飞达出标完成,
        吸标NG取标流程,

    }
    public enum e_Flow_Labeling
    {
        等待开始检测产品信号,
        检查产品有无,
        治具定位,
        等待治具定位结果,

        放行治具,
        取标签,
        等待飞达出标,
        到拍照位拍照,
        等待拍照结果,
        定位OK待放标签,
        放标签,
        到贴标位拍照,
        等待检测结果,

        贴标NG放至NG输送上,
        进料NG放至NG输送上,
    }
    public enum e_PosCut
    {
        撕膜等料位,
        撕膜水平位,
        夹膜位,
        撕膜过度位,
        撕膜终点位,
        撕膜垃圾位,
        撕膜安全位,
    }

    public enum e_Step_Label
    {
        取标气缸抬起,
        取标气缸下压,
        移至取标位上方,
        取标位向下移动,
        取标签吸真空,
        放标签破真空,
        移至拍照位,
        移至拍照NG位上方,
        拍照NG位向下移动,
        移至OK位上方,
        OK位向下移动,
        拍照,
        移至NG取工装位上,
        移至NG放工装位上,
        NG取工装位下降,
        NG放工装位下降,
        NG取工装位上升,
        NG放工装位上升,
        NG取工装吸真空,
        NG放工装破真空,
        移至拍照安全位X,
        移至拍照检测位,
        拍照检测上,
        检测吸标靶面真空,
        移至NG取工装时贴标Z轴安全位,
        飞达吹气,
        飞达关气,
        贴标前定位拍照,
        等待贴标前定位拍照,
        吸标NG旋转到取标位,
        吸标NG旋转到放标位,
        吸标NG下压,
        吸标NG抬起,
        吸标NG吸气,
        吸标NG破气,
        移至拍照检测位上,
        移至拍照检测位下,
        拍照检测下,
        文字版快换气缸松开,
        文字版快换气缸夹紧,
        拍照复检,
    }
    public enum e_platePro
    {
        双平台无,
        平台1,
        平台2,
        双平台有
    }
    public enum e_Manual_Air
    {
        入料段治具阻挡,
        入料段治具放行,
        一段治具阻挡,
        一段治具放行,
        一段治具升起,
        一段治具下降,
        二段治具阻挡,
        二段治具放行,
        二段治具升起,
        二段治具下降,

        取标气缸抬起,
        取标气缸下压,
        取标签吸真空,
        放标签破真空,
        NG取工装吸真空,
        NG放工装破真空,

        吸标NG下压,
        吸标NG抬起,
        吸标NG吸气,
        吸标NG破气
    }
    public enum e_airResult
    {
        双平台吸无料 = 20,
        平台1已吸有料 = 21,
        平台2已吸有料 = 22,

        双平台已吸有料 = 23,
    }
    public enum e_Flow_Fly
    {
        等待触发飞达,
        等待标签到位,
        等待标签下降沿,
        标签到位,
        等待拍照,
        拍照结果输出
    }
    public enum e_Step_ConveryUp
    {
        上层输送治具,
        入料段治具阻挡,
        入料段治具放行,
        一段治具阻挡,
        一段治具放行,
        一段治具升起,
        一段治具下降,
        二段治具阻挡,
        二段治具放行,
        二段治具升起,
        二段治具下降,

    }

    public enum e_Flow_ConveryUp
    {
        等待入料治具到位,
        入料治具到位,
        入料成功,

        等待一段治具到位,
        一段治具到位,
        等待一段加工完成,
        一段治具加工完成,
        一段放行,
        等待一段治具离开,

        等待二段治具到位,
        二段治具到位,
        等待二段加工完成,
        二段治具加工完成,
        二段写入信息与放行,
        等待二段治具离开,
        上层下游交互,
        送料中途下游停止要料,

        等待人工站到达,
        等待人工站处理完成,
        人工站写入信息并放行
    }

    public enum e_input_card1
    {
        上层上游物料OK,
        上层上游物料NG,
        下层向本机要料,
        上层向本机要料,
        下层物料OK,
        人工过站
    }
    public enum e_output_card1
    {
        上层向上游要料,
        下层物料放行,
        上层物料OK,
        上层物料NG,
        下层要料
    }
    public enum e_input_extCard1
    {
        贴标气缸到位1,
        贴标气缸到位2,
        上层阻挡气缸到位1,
        上层阻挡气缸到位2,
        上层阻挡气缸到位3,
        上层顶升气缸到位1,
        上层顶升气缸到位2,
        下层阻挡气缸到位1,
        飞达1平台有料,
        飞达2平台有料,
        平台2吸标NG抬起到位,
        平台2吸标NG放料位,
        平台2吸标NG取料位,
        平台1吸标NG取料位,
        平台1吸标NG抬起到位,
        平台1吸标NG放料位,
    }
    public enum e_output_extCard1
    {
        吸标靶面快换夹具1,
        吸标靶面快换夹具2,
        撕膜后除尘,
        撕膜垃圾位吹膜,
        平台2取标旋转,
        平台2取标抬起,
        平台1取标旋转,
        平台1取标抬起,
        NG取标吸气2,
        NG取标吸气1
    }

    public enum e_input_extCard2
    {
        飞达1测标光纤1,
        限位接近开关1,
        限位接近开关2,
        飞达1测标光纤2,
        上输送产品检测1,
        上输送产品检测2,
        上输送产品检测3,
        上输送产品检测4,
        NG输送产品检测1,
        NG输送产品检测2,
        NG输送产品检测3 = 10,

        上输送治具检测1,
        上输送治具检测2,
        上输送治具检测3,
        上输送治具检测4,
        下输送治具检测1,
        吸标靶面真空报警1,
        吸标靶面真空报警2,
        总气源压力报警,
        飞达2测标光纤1,
        复位按钮 = 20,

        飞达2测标光纤2,
        急停按钮,
        门禁开关,
        贴标升降气缸原点1,
        贴标升降气缸原点2,
        上层阻挡气缸原点1,
        上层阻挡气缸原点2,
        上层阻挡气缸原点3,
        上层顶升气缸原点1,
        上层顶升气缸原点2,
        下层阻挡气缸原点1,
    }
    public enum e_output_extCard2
    {
        飞达吹气1,
        飞达离子吹风电源1,
        飞达吹气2,
        飞达离子吹风电源2,
        预留,
        上层阻挡气缸1,
        上层阻挡气缸2,
        上层阻挡气缸3,
        上层顶升气缸1,
        上层顶升气缸2,
        下层阻挡气缸1 = 10,

        撕膜气缸1,
        撕膜气缸2,
        贴标Z轴刹车,
        贴标升降气缸1,
        吸标靶面吸气1,
        NG真空吸产品2,
        贴标升降气缸2,
        吸标靶面吸气2,
        NG真空吸产品1,
        LED照明灯 = 20,

        定位相机触发,
        扫码相机触发,
        红灯,
        绿灯,
        黄灯,
        蜂鸣器,
        飞达下相机,
        废料离子风
    }

    public enum e_Card
    {
        Card1,
        CardEx1,
        CardEx2
    }

    public enum e_measureStatus
    {
        OK = 0,
        singleTol = 1,
        Max_min = 2,
        singleAndMaxMin = 3,
        noJudge = 100
    }
    public enum e_ConveryControl
    {
        上层输送反转,
        上层输送启动,
        上层输送停止,
        下层输送启动,
        下层输送停止,
        NG输送启动,
        NG输送停止,
        下层治具放行,
        下层治具阻挡,
    }

    public enum e_card1_axis
    {
        下层输送左,
        下层输送右,
        上层输送左,
        上层输送右,
        贴标R1下,
        贴标R2上,
        贴标X1下,
        贴标X2上,
        贴标Y轴,
        NG输送,
        一段压产品Z,
        飞达牵引2,
        飞达牵引1,
        剔除Z轴,
        贴标Z轴,
        撕膜R2,
        撕膜X,
        撕膜Z,
        撕膜Y,
        撕膜R1,
    }
    public class AlarmInfo
    {
        public DateTime startTime { get; set; }
        public string AlarmMsg { get; set; }
        public string ProIds { get; set; }
    }
    public class SigleAxisSafe
    {
        public int nAxis { get; set; }
        /// <summary>
        /// 目标位置
        /// </summary>
        public double pos { get; set; }
    }
    public class ProductInfo
    {
        /// <summary>
        /// 产品编号
        /// </summary>
        public int ProNo { get; set; }
        /// <summary>
        /// 工装ID
        /// </summary>
        public string ProId { get; set; }
        /// <summary>
        /// 时间
        /// </summary>
        public DateTime? LaserTime { get; set; }
        /// <summary>
        /// 标签时间
        /// </summary>
        public DateTime? LabelTime { get; set; }
        /// <summary>
        /// 配方
        /// </summary>
        public string typeName { get; set; }
        /// <summary>
        /// 收到上游结果
        /// </summary>
        public string Result_up { get; set; } = e_Result.未知.ToString();
        /// <summary>
        /// 发给下游结果
        /// </summary>
        public string Result_down { get; set; } = e_Result.未知.ToString();
        /// <summary>
        /// 结果
        /// </summary>
        public string Result { get; set; } = e_Result.未知.ToString();
        /// <summary>
        /// 撕膜结果
        /// </summary>
        public string Result_Cut { get; set; } = e_Result.未知.ToString();
        /// <summary>
        /// 贴膜结果
        /// </summary>
        public string Result_Label { get; set; } = e_Result.未知.ToString();
        /// <summary>
        /// 0无故障  1有故障  
        /// </summary>
        public int IsProcessAlarm { get; set; } = 0;
        /// <summary>
        /// 故障时间
        /// </summary>
        public DateTime? AlarmTime { get; set; }
        /// <summary>
        /// 出料RFID
        /// </summary>
        public string ProId_out { get; set; }
    }
    public enum e_Result
    {
        未知,
        进料OK,
        进料NG,
        进料读卡NG,
        撕膜OK,
        撕膜NG,
        扫码OK,
        扫码NG,
        贴膜NG,
        贴膜OK,
        写入读卡器OK,
        写入读卡器NG,
        出料OK,
        出料NG
    }
    #endregion
    public class SigleAxis
    {
        public double velrate { get; set; } = 1;
        /// <summary>
        /// 是不是绝对运动
        /// </summary>
        public bool IsAbs { get; set; }
        /// <summary>
        /// 轴号
        /// </summary>
        public int nAxis { get; set; }
        /// <summary>
        /// 目标位置
        /// </summary>
        public double pos { get; set; }
    }
    [Serializable]
    public class AbsPostion
    {
        /// <summary>
        /// x
        /// </summary>
        public double X { get; set; }
        /// <summary>
        /// Y
        /// </summary>
        public double Y { get; set; }
        /// <summary>
        /// R
        /// </summary>
        public double R { get; set; }
        /// <summary>
        /// Z
        /// </summary>
        public double Z { get; set; }
        public double ZHeight { get; set; }

    }
    public enum e_FlowConveryDown
    {
        下层等待要料,
         下层送料,
         下层等待载具到位
    }
    [Serializable]
    public class NGPostion
    {

        /// <summary>
        /// Y
        /// </summary>
        public double Y { get; set; }
        /// <summary>
        /// R
        /// </summary>
        public double Zup { get; set; }
        /// <summary>
        /// Z
        /// </summary>
        public double Zdown { get; set; }

    }
    [Serializable]
    public class xPostion
    {
        public double X;
        public double Y;
        public double Angle;
    }
}
